NAME

DBIO::Oracle::Diff::ForeignKey - Diff operations for Oracle foreign keys

VERSION

version 0.900007

DESCRIPTION

Creates the foreign keys of a table that only the target model has, each as an ALTER TABLE ... ADD CONSTRAINT after every CREATE TABLE of the diff: a new table may point to one that is created after it, or to itself, so no table order would do (DBIO::Oracle::DDL does the same).

The foreign keys of a table both models have are compared. A key is what it is, not what it is called: its columns, the referenced table and columns, on_delete, on_update and is_deferrable; the names of the constraints do not count, and a missing section counts as empty. A key only the source has is dropped (ALTER TABLE ... DROP CONSTRAINT, by the name the introspected source model gives it), one only the target has is added, and a key that changed (an action, the columns, the target) is both, the drop first. A key over a column the target drops is not dropped here: the column goes with CASCADE CONSTRAINTS (DBIO::Oracle::Diff::Column).

The statement is the one the install writes: the name of the constraint, the columns, the referenced table and columns, ON DELETE CASCADE or ON DELETE SET NULL (NO ACTION is Oracle's behaviour and writes nothing; RESTRICT is written as NO ACTION, as the DDL does) and DEFERRABLE for a deferrable key. The name is the one of the model; a key without one gets the install's, fk_<table>_<columns>_<target> shortened to 30 characters. Oracle has no ON UPDATE and no ON DELETE SET DEFAULT: a key to be created with one is refused with a DBIO::Exception naming the table and the columns, as DBIO::Oracle::DDL refuses it.

ATTRIBUTES

table_name

The key of the table that holds the key: a bare name, or schema.table.

constraint_name

The name of the constraint.

fk_info

Hashref of the key from the model: from_columns, to_table, to_columns, on_delete, on_update, is_deferrable.

METHODS

diff

my @ops = DBIO::Oracle::Diff::ForeignKey->diff(
    $source_fks, $target_fks, $source_tables, $target_tables, $target_columns,
);

The foreign_keys sections of the two models (keyed by table, each an arrayref of keys), their tables and the columns section of the target (which columns a table keeps). For a table in both table sets: a drop op for each key only the source has and a create op for each key only the target has. For a table only in the target tables: a create op for each of its keys. In the order of the table names and of the keys of the model; the drops of a table come before its creates.

create_op

my $op = DBIO::Oracle::Diff::ForeignKey->create_op($table, $fk);

The create op for the key $fk of the model on $table, with the checks of diff: a delete or update rule Oracle does not have throws a DBIO::Exception naming the table and the columns. on_delete RESTRICT is Oracle's NO ACTION and written as such (no clause), as DBIO::Oracle::DDL does.

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.