NAME
DBIO::PostgreSQL::Diff::Schema - Diff operations for PostgreSQL schemas
VERSION
version 0.900007
DESCRIPTION
Represents a single schema (namespace) diff operation: CREATE SCHEMA or DROP SCHEMA. Instances are produced by the "diff" class method and consumed by DBIO::PostgreSQL::Diff.
ATTRIBUTES
schema_name
The PostgreSQL schema name being created or dropped.
if_missing
True for a create whose entry in the target model carries create_if_missing, which DBIO::PostgreSQL::Deploy sets on the namespace of a connection with the connect key schema. The statement then looks the schema up in pg_namespace and creates it only where it is missing ("create_schema_if_missing" in DBIO::PostgreSQL::Util).
METHODS
diff
my @ops = DBIO::PostgreSQL::Diff::Schema->diff(
$source, $target, $source_extensions, $target_extensions,
$source_outside_dependents);
Compares two schema hashrefs (as from DBIO::PostgreSQL::Introspect::Schemas) and returns a list of DBIO::PostgreSQL::Diff::Schema objects representing schemas to create or drop.
The optional $source_extensions / $target_extensions hashrefs are the extensions sections of the two models (threaded in by DBIO::PostgreSQL::Diff via its aux-section wiring). With them, a drop is refused when an extension the diff keeps -- one in both sections -- is installed in the schema: the extension depends on that schema, so the server refuses the DROP SCHEMA for it, and the one way to make it pass is CASCADE, which would drop the extension as well, and with it every column of a type it brings, in tables the diff was never asked to touch. The diff dies with refusing to diff: ..., naming the schema and the extension, and generates no statement. An extension that goes in the same diff is no obstacle: it is dropped ahead of its schema ("ORDER OF OPERATIONS" in DBIO::PostgreSQL::Diff). Without the two arguments nothing is checked.
A schema to create whose name differs only in upper and lower case from one to drop -- Auth in the target, auth in the database -- is refused as well (DBIO::PostgreSQL::Diff::CaseOnly): DROP SCHEMA auth comes after the drop of every table in it, and its rows. The message names both and the way out, ALTER SCHEMA auth RENAME TO "Auth". Schemas are the first section the diff looks at, so this is what is said of such a database -- not that every table in auth goes and every table in Auth comes.
A deploy that is restricted by "pg_schemas" in DBIO::PostgreSQL does not get here with such a pair: its models hold the declared schemas only ("_schema_filter" in DBIO::PostgreSQL::Deploy), so an auth beside a declared Auth is not in them. Its diff creates Auth and everything declared in it, and leaves auth and its rows where they are -- nothing is lost and nothing is said.
A schema is dropped without CASCADE. The order of the operations has dropped what the model holds in it by then: its tables, views, types, functions and the sequences no column owns ("What is not done" in DBIO::PostgreSQL::Diff::Sequence), the extensions that go. What stands in it and the model does not hold -- a domain, an operator, a collation, an operator class or family, a conversion, a statistics object, a text search object -- is read into the outside_dependents section (the fifth argument, the section of the source model) and refused by name: refusing to diff: ... and no statement (DBIO::PostgreSQL::Diff::Dependents). Anything else in the schema stops the DROP SCHEMA itself, and the transaction apply runs in leaves the database as it was.
as_sql
Returns the SQL statement for this operation: CREATE SCHEMA name; or DROP SCHEMA name;. For an action this class does not know it dies ("throw" in DBIO::PostgreSQL::Diff::NoStatement).
summary
Returns a one-line human-readable description such as +schema: auth or -schema: old_ns.
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.