NAME
DBIO::DB2::Diff - Compare two introspected DB2 models
VERSION
version 0.900007
DESCRIPTION
DBIO::DB2::Diff compares two introspected DB2 models (produced by DBIO::DB2::Introspect) and emits a list of structured diff operations that can be rendered to SQL or a human-readable summary.
my $diff = DBIO::DB2::Diff->new(
source => $current_model,
target => $desired_model,
);
if ($diff->has_changes) {
print $diff->as_sql;
print $diff->summary;
}
Operations are emitted in dependency order: the views that are dropped (or dropped to be replaced) first, then tables, then columns, then the REORG some column changes make necessary, then indexes, then unique constraints, then foreign keys. New-table unique constraints and FKs are created inline by DBIO::DB2::Diff::Table; DBIO::DB2::Diff::ForeignKey handles FK changes on tables present in both models. FKs come last so any referenced table or column already exists. Drops come last for each layer. The views that are created come after everything else. A view is no table: it has operations of its own (DBIO::DB2::Diff::View), a changed definition is a DROP VIEW and a CREATE VIEW around all of it (ADR 0011).
REORG after the column pass
DROP COLUMN, SET NOT NULL, DROP NOT NULL and nearly every SET DATA TYPE leave a Db2 table in reorg-pending state, in which the server refuses INSERT, UPDATE and CREATE INDEX on it (SQL0668N rc 7). So after the column pass every table with such an operation ("reorg_recommended" in DBIO::DB2::Diff::Column) gets one DBIO::DB2::Diff::Reorg operation -- CALL SYSPROC.ADMIN_CMD('REORG TABLE ...') -- and the index and foreign key passes run on a table that takes them. The REORG is in "as_sql" in DBIO::Diff::Base and "summary" in DBIO::Diff::Base like any other operation: it rewrites the table, and a diff is where an operator reads what an upgrade is going to do. A table that is already reorg-pending before the diff is made gets none; see DBIO::DB2::Diff::Reorg and ADR 0008.
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.