NAME

DBIO::PostgreSQL::Diff::Trigger - Diff operations for PostgreSQL triggers

VERSION

version 0.900007

DESCRIPTION

Represents a trigger-level diff operation: CREATE TRIGGER or DROP TRIGGER. When a trigger definition changes, it produces a DROP followed by a CREATE. Triggers are compared using the full pg_get_triggerdef output.

ATTRIBUTES

table_key

The schema.table key identifying which table the trigger belongs to. It is where the model files the table, and what "summary" prints; it is not SQL.

schema_name

The schema of that table.

table_name

The name of that table. "as_sql" writes the table from schema_name and table_name, each quoted for itself -- the key cannot be taken apart again, a schema or a table may have a dot in its name. "diff" takes both from the trigger entry. An operation built by hand without them falls back to the key ("key_names" in DBIO::PostgreSQL::Introspect).

trigger_name

The trigger name.

trigger_info

Trigger metadata hashref (definition, timing, event, etc.).

replaced

True on the drop of a changed trigger: the trigger is not removed, the create that follows puts it back with its new definition. It tells DBIO::PostgreSQL::Diff to leave the two together instead of moving the drop to the removals ("ORDER OF OPERATIONS" in DBIO::PostgreSQL::Diff).

METHODS

diff

my @ops = DBIO::PostgreSQL::Diff::Trigger->diff(
  $source, $target, $source_tables, $target_tables);

Compares trigger sets per table. Definition changes produce a drop-then-create pair.

The optional $source_tables / $target_tables hashrefs are the tables sections of the two models (threaded in by DBIO::PostgreSQL::Diff via its aux-section wiring). They tell which views this diff drops and creates again ("rebuilt" in DBIO::PostgreSQL::Diff::View). DROP VIEW takes the triggers of the view with it, so for such a view every trigger the target has is created, changed or not, and none is dropped. The columns sections of the two models, when given after them, add the views that are rebuilt for the type of a column they read. Without the two arguments no view is taken to be rebuilt.

A trigger to create -- a new one, a changed one, one of a rebuilt view -- that the target model has no definition for is refused, with refusing to diff: ... and no statement (DBIO::PostgreSQL::Diff::NoStatement): the definition is all the diff writes a trigger from, and all it compares one by. For a changed trigger the DROP would be all that is left of the pair. pg_get_triggerdef gives none for a trigger another session dropped while the model was read. A trigger only the source lacks the definition of is dropped and created like any other whose definition differs, and a drop needs none.

as_sql

Returns CREATE TRIGGER ...; using the full definition from introspection, or DROP TRIGGER name ON table;.

A definition from pg_get_triggerdef is the server's own text and is written as given. In the DROP, trigger and table are identifiers by the server's rule ("quote_ident" in DBIO::PostgreSQL::Util).

A create whose trigger_info has no definition has no statement, and neither has an action this class does not know: as_sql dies ("throw" in DBIO::PostgreSQL::Diff::NoStatement) and returns no comment in its place. "diff" builds no such operation; one built by hand can be.

summary

Returns a one-line description such as +trigger: users_modified_at on auth.users.

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.