NAME
DBIO::PostgreSQL::Diff::CaseOnly - A name that differs from one in the database only in case is not a new object
VERSION
version 0.900007
SYNOPSIS
use DBIO::PostgreSQL::Diff::CaseOnly ();
use DBIO::PostgreSQL::Util qw(quote_ident quote_qualified);
# in the diff method of an operation class, ahead of everything else
my @pairs = DBIO::PostgreSQL::Diff::CaseOnly->pairs(
[ map { { in => [ $_->{schema_name} ], name => $_->{table_name} } } values %$source ],
[ map { { in => [ $_->{schema_name} ], name => $_->{table_name} } } values %$target ],
);
DBIO::PostgreSQL::Diff::CaseOnly->refuse(
'DROP TABLE takes its rows.',
map {
my ($old, $new) = @$_;
my $schema = $old->{in}[0];
{
kind => 'table',
database => "$schema.$old->{name}",
target => "$schema.$new->{name}",
rename => sprintf('ALTER TABLE %s RENAME TO %s;',
quote_qualified($schema, $old->{name}), quote_ident($new->{name})),
}
} @pairs,
);
DESCRIPTION
PostgreSQL reads a name written without quotes in lower case and a quoted one exactly. A database built from statements that wrote UserAccount bare holds useraccount; a statement that quotes it makes "UserAccount". One object is easily known under two spellings that way, and DBIO::PostgreSQL::Diff compares names as they are: it sees an object to create and another to drop. For a table that is CREATE TABLE "UserAccount" and DROP TABLE useraccount, and the rows are gone.
The rule that answers this stands here, once, for every operation class that drops something the database cannot get back:
A name the target has and the database does not, and a name the database has and the target does not, that are the same but for upper and lower case, are not taken for two objects. The diff does not know they are one, and it does not know they are two, so it is refused -- refusing to diff: ..., see "WHAT IS REFUSED" in DBIO::PostgreSQL::Diff -- and the message names both and the RENAME that makes the one into the other.
The diff does not write that RENAME itself. Whether it should is an open question of the family (core ADR 0060); until it is answered, the one who knows whether the two are the same object decides.
Which classes ask, and which leave a pair of this kind to be dropped and created, is listed under "WHAT IS REFUSED" in DBIO::PostgreSQL::Diff.
METHODS
pairs
my @pairs = DBIO::PostgreSQL::Diff::CaseOnly->pairs(\@source, \@target);
Finds the names that differ only in case. @source is what the database has and @target what the target has, each entry a hashref with
name-- the name, as the catalog has itin-- an arrayref of the names that say where it is a name: the schema of a table, the schema and the table of a column, nothing for a schema. Two names are only ever compared within the same place, and the place is compared exactly:auth.usersandAuth.usersare tables in two schemas, and it is the schemas that differ in case.
and whatever else the caller wants to find again. Returns a list of [ $source_entry, $target_entry ], in the order of the places and, within one, of the target's names.
A pair is an entry only the target has and an entry only the source has, in the same place, whose names are equal in lower case. A name both sides have never pairs: a target with users and Users beside a database with users has a second table to create, and a database with both beside a target with Users has one to drop. Where one name matches several on the other side -- users and USERS to drop, Users to create -- each is a pair of its own.
The names are compared with Perl's lc. That is wider than what the server does to a bare name -- it lowers the letters A to Z and, in a database in UTF-8, no other -- and errs to the side of asking.
refuse
DBIO::PostgreSQL::Diff::CaseOnly->refuse($would, @found);
Dies with the refusal for @found, and returns when there is none. Each entry of @found is a hashref:
kind-- what the object is, as a reader calls it:table,column,schemadatabase,target-- the object's full name on either side, as a reader sees it, unquoted (public.useraccount,public.UserAccount)rename-- the statement that gives the object in the database the target's name, its identifiers written by "quote_ident" in DBIO::PostgreSQL::Util
$would is a sentence saying what dropping the one in the database does: what goes with it, or why the server does not take the statement. It is a line of the message, or several with a newline between them.
All of @found is in the one message, each with its rename: a schema declared in Mixed Case has more than one such table, and a refusal for each would be a run for each.
SEE ALSO
"quote_ident" in DBIO::PostgreSQL::Util - the server's rule for a name in a statement
AUTHOR
DBIO & DBIx::Class Authors
COPYRIGHT AND LICENSE
Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.