NAME
DBIO::Informix::Diff::ForeignKey - Diff operations for Informix foreign keys
VERSION
version 0.900007
DESCRIPTION
Represents a foreign key diff operation on a table that exists in both models: ALTER TABLE ... ADD CONSTRAINT FOREIGN KEY ... or ALTER TABLE ... DROP CONSTRAINT. The keys of a brand-new table are added the same way, after every CREATE TABLE (never inline: the referenced table may be created later in the same diff). Keys of a table that is dropped go with the table.
Keys are compared by what they say, not by name: columns, target table, target columns and the delete action. Informix has no ON UPDATE. The name the server gives a key without one, r <tabid>_<n> (written r136_41, no blank), differs from one database to the next and is never a difference. The name (constraint_name; the raw introspector key fk_name is read as well) serves only to drop a key. A key is added without a name, unless the model names one that is not a server-assigned one. A changed key becomes a drop followed by an add. A key to drop whose model holds no name dies at as_sql, naming the table.
The syntax is the documented Informix one (constraint name after the definition):
ALTER TABLE t ADD CONSTRAINT FOREIGN KEY (a, b) REFERENCES r (x, y)
[ON DELETE CASCADE] CONSTRAINT name;
ALTER TABLE t DROP CONSTRAINT name;
Live unmeasured: there is no Informix server nor a buildable DBD::Informix here; the statements are written from the IBM/HCL documentation and have never run against a server.
Rules, source: sysreferences.delrule is CHAR(1): C cascading delete, R restrict (the default); updrule and matchtype are documented as reserved for future use and always show R and N (HCL OneDB SQL reference, sysreferences table, https://help.hcl-software.com/onedb/1.0.1/sqr/ids_sqr_055.html; the same text is in the IBM Informix SQL reference).
Refusal: Informix knows exactly one referential action, ON DELETE CASCADE; there is no ON UPDATE. Every other action (on_delete / on_update, or the raw del_rule / upd_rule, with a value other than the default) is refused with a die naming table, constraint and reason, for a key of an existing table as well as for one of a new table, instead of being left out silently. Silent defaults: undefined or empty, NO ACTION, RESTRICT, raw R; cascade is CASCADE or raw C on the delete side. DISABLED/INDEX DISABLED modes are not modelled.
ATTRIBUTES
replaced
True for the drop of a foreign key that comes back in the same diff as an add of the same table and the same name (a changed key, or one rebuilt around a constraint it references): the first half of a change, not destructive (core ADR 0080, "destructive_operations" in DBIO::Diff::Base). A key the server named itself comes back as a key over the same columns. A key that disappears is destructive.
METHODS
fk_name
my $name = DBIO::Informix::Diff::ForeignKey::fk_name($table, $fk);
The name of a key, for messages and summaries: constraint_name, else fk_name, else the descriptive fk_<table>_<cols>_<target>. It is not written into SQL unless the model names the key (see fk_clause).
fk_clause
my $sql = DBIO::Informix::Diff::ForeignKey::fk_clause($table, $fk);
FOREIGN KEY (...) REFERENCES r (...) [ON DELETE CASCADE] [CONSTRAINT name], used by the ALTER TABLE ... ADD CONSTRAINT. The name is left out when the model names none or only a server-assigned one.
diff
my @ops = DBIO::Informix::Diff::ForeignKey->diff(
$source_fks, $target_fks, $source_tables, $target_tables,
$dropped_keys,
);
$dropped_keys (optional) is a hash reference whose keys name the unique constraints dropped in the same diff, as the table, a NUL and the sorted column names joined by NUL (DBIO::Informix::Diff::UniqueConstraint::dropped_keys). A key that stays but references one of them is dropped and added again.
as_sql
summary
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.