NAME

DBIO::Sybase::Diff::ForeignKey - Diff Sybase ASE foreign keys

VERSION

version 0.900007

DESCRIPTION

Compares two foreign-key sets and generates FK-level diff operations. Given the two table models (as DBIO::Sybase::Diff passes them), it walks every table of the target: a retained table has its FKs reconciled -- a table without any FK on one side counts as an empty list there, not as absent -- and a brand-new table gets every FK of its own as an ADD CONSTRAINT, which DBIO::Sybase::Diff runs after all CREATE TABLEs. FKs on a dropped table vanish with it.

The diff reads the table models next to the FK models, so a table missing from either FK model is still diffed: the first FK added to a table, the last one dropped from it, and the FKs of a new table (which CREATE TABLE does not carry) all reach the diff. Called without table models (the unit-level form), a table is still diffed only when both FK models name it.

The introspected per-constraint FK shape (produced by "_group_fks_by_constraint" in DBIO::Sybase::Introspect) is { constraint_name, from_columns, to_table, to_columns, on_update, on_delete }. FK identity here is the relationship tuple from_columns -> to_table(to_columns) (not the name, since the desired/target model built from a schema definition has no live name); the alterable attributes are on_update / on_delete.

DROP (and the drop-half of an alter) prefers the real, server-assigned constraint_name carried on the source (live/introspected) entry, so a foreign key created out-of-band under any name is dropped by its actual name. CREATE (and the create-half of an alter) targets the desired model, which has no live name, so it falls back to a deterministic generated name derived from the relationship tuple (fk_<table>_<cols>, the same approach the DDL emitter uses for unnamed unique indexes). When the source entry also lacks a name, DROP falls back to the same generated name.

Sybase ASE cannot alter an FK constraint in place, so an attribute change becomes a drop-then-add pair.

ASE has no referential actions (Msg 156, for NO ACTION too), so a create whose model carries an on_update or on_delete other than NO ACTION (undef and the empty string mean none) throws a DBIO::Exception from as_sql, naming constraint, table, event and value, instead of writing ON DELETE ... the server refuses. DBIO::Sybase::DDL refuses the same declaration at install time.

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.