NAME
DBIO::PostgreSQL::Diff::Type - Diff operations for PostgreSQL types (enums, composites, ranges)
VERSION
version 0.900007
DESCRIPTION
Represents a type-level diff operation: CREATE TYPE, DROP TYPE, or ALTER TYPE ... ADD VALUE (for enum value additions). Handles enum, composite, and range types. Note that enum value removal is not supported by PostgreSQL -- only addition is possible without recreating the type.
ATTRIBUTES
type_key
The schema.type_name key.
type_info
Type metadata hashref from introspection (type_kind, values, attributes, or subtype depending on kind).
added_values
For an add_value operation: arrayref of the enum values the target has and the source does not, in the order the target has them. "as_sql" writes one ALTER TYPE ... ADD VALUE for each. Not set for create and drop.
value_positions
For an add_value operation: arrayref of { value => $v, after => $w }, { value => $v, before => $w } or { value => $v }, one for each of "added_values", which "as_sql" writes as ADD VALUE 'v' AFTER 'w', BEFORE 'w' or without a position. Without an entry (an operation built by hand) a value is added with no position.
METHODS
diff
my @ops = DBIO::PostgreSQL::Diff::Type->diff(
$source, $target, $source_outside_dependents);
Compares two type hashrefs. Produces create operations for new types, drop for removed types, and add_value for enum types that have gained new values.
A type to create whose name differs only in upper and lower case from one to drop, of the same kind and in the same schema -- Role_Type in the target, role_type in the database -- is refused, with refusing to diff: ... and no statement (DBIO::PostgreSQL::Diff::CaseOnly). The two are most likely one type. Taken for two, a column of the one is altered to the other ahead of the drop, which PostgreSQL does not do without a cast, and the drop would meet every column that is still of the old one. The message names both, for every such type at once, and the way out: ALTER TYPE auth.role_type RENAME TO "Role_Type".
A type both sides have that differs in more than enum values added to the ones the database has is refused the same way, naming every such type, what differs and the way out, and no statement is written:
a type that is of another kind in the target (an enum where the database has a composite type, ...)
an enum or a composite type the target declares empty (no values, no attributes) where the database has some. The model carries an empty type as an entry with an empty list, which tells it from a type the target does not declare at all (that one is a plain
DROP TYPE). Written as a drop it would take every column of the type with its rowsan enum that has lost a value (PostgreSQL has no
DROP VALUE), or has its values in another order. A value added between the ones the database has is not refused: it is written with its position, and an upgrade does not reorder the ones the database hasa composite type with other attributes (added, dropped, renamed, of another type or size, or with another collation of its own):
ALTER TYPE ... ADD ATTRIBUTEand its relatives exist, but the diff does not write thema range type with another subtype, another collation, another operator class (
subtype_opclass, where it is not the subtype's default) or anothercanonicalorsubtype_difffunction. The model carries these keys only where a range sets them (DBIO::PostgreSQL::Introspect::Types), and a model without them is read as a range that sets none; before they were in the model such a difference gave no operation and no message
A type that is created is created with all of these (CREATE TYPE ... AS RANGE (SUBTYPE = ..., SUBTYPE_OPCLASS = ..., COLLATION = ..., CANONICAL = ..., SUBTYPE_DIFF = ...), name type COLLATE ... for an attribute), so that the diff after it is empty.
A type that moves to another schema or is renamed is a type to create and a type to drop: the columns of it are altered to the new one with USING col::text::new_type in between (DBIO::PostgreSQL::Diff::Column), and DROP TYPE comes last.
A type is dropped without CASCADE. The order of the operations has dropped what the model holds on it by then -- the columns that are of it are altered to another type, the functions that take it are gone -- and a type that another dropped type is built on (an attribute of a composite type, the subtype of a range) is dropped after the type built on it. What is not in the model and stands on the type -- a column of a table in a schema outside pg_schemas, a function or procedure of such a schema that takes or returns it, a domain over it -- is read into the outside_dependents section (the third argument, the section of the source model) and refused by name: refusing to diff: ... and no statement (DBIO::PostgreSQL::Diff::Dependents). Anything else that depends on the type stops the DROP TYPE itself, and the transaction apply runs in leaves the database as it was.
An enum value added between two the database has, or ahead of all of them, is written with its position -- ADD VALUE 'c' AFTER 'a', or BEFORE 'a' for a value that comes first -- so the type has the target's order afterwards and the next diff is empty. The position names the value before it in the target (a new one is written ahead of it), or the first value the database has. A value with no value the database has behind it is added with no position. See "value_positions".
as_sql
Returns the SQL for this operation. For add_value, returns one ALTER TYPE ... ADD VALUE statement per new enum value.
The type is written from the schema_name and type_name of its type_info, each quoted for itself by the server's rule ("quote_ident" in DBIO::PostgreSQL::Util) -- not from "type_key", which is where the model files the type and cannot be taken apart again. A type_info without the names falls back to the key ("key_names" in DBIO::PostgreSQL::Introspect). Enum values are written as literals ("quote_literal" in DBIO::PostgreSQL::Util), the attribute names of a composite type as identifiers; attribute types and a range's subtype come from the catalog (format_type) and are written as given, and so are a collation, an operator class and the canonical and subtype_diff functions, which the model holds quoted with their schema.
A create of a type that is none of the three kinds has no statement, and neither has a range type without a subtype, an add_value without values or an action this class does not know: as_sql dies ("throw" in DBIO::PostgreSQL::Diff::NoStatement). The model has no such type from DBIO::PostgreSQL::Introspect::Types; an operation built by hand can.
summary
Returns a one-line description such as +type: auth.role_type (enum) or ~type: auth.role_type +1 value(s) (superadmin).
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.