| 1 | package DBIO::DB2::Diff; | ||
| 2 | # ABSTRACT: Compare two introspected DB2 models | ||
| 3 | |||
| 4 | 45 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 45 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 45 | our $VERSION = '0.900007'; | |
| 8 | |||
| 9 | 45 | ▶ | use base 'DBIO::Diff::Base'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 45 | ▶ | use DBIO::DB2::Diff::Table; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 45 | ▶ | use DBIO::DB2::Diff::Column; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 45 | ▶ | use DBIO::DB2::Diff::Reorg; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | 45 | ▶ | use DBIO::DB2::Diff::Index; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | 45 | ▶ | use DBIO::DB2::Diff::UniqueConstraint; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | 45 | ▶ | use DBIO::DB2::Diff::ForeignKey; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | 45 | ▶ | use DBIO::DB2::Diff::View; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | |||
| 19 | |||
| 20 | 155 | ▶ | sub _build_operations { |
|
Subroutine
_build_operations: called CC=1 SCAR=0.0
| |||
| 21 | 155 | my ($self) = @_; | |
| 22 | 155 | my @ops; | |
| 23 | |||
| 24 | # Views are no tables (karr k45, ADR 0011): the ops of a view are a DROP VIEW | ||
| 25 | # at the head -- a table a view reads can then go -- and a CREATE VIEW at the | ||
| 26 | # end, behind the tables, columns and keys it reads. Diff::Table and | ||
| 27 | # Diff::Column leave every entry of kind view alone. | ||
| 28 | my @view_ops = DBIO::DB2::Diff::View->diff( | ||
| 29 | $self->source->{tables}, $self->target->{tables}, | ||
| 30 | 155 | ); | |
| 31 | 153 | push @ops, grep { $_->action eq 'drop' } @view_ops; | |
| 32 | |||
| 33 | push @ops, DBIO::DB2::Diff::Table->diff( | ||
| 34 | $self->source->{tables}, $self->target->{tables}, | ||
| 35 | $self->target->{columns}, $self->target->{foreign_keys}, | ||
| 36 | $self->target->{unique_constraints}, | ||
| 37 | 153 | ); | |
| 38 | my @column_ops = DBIO::DB2::Diff::Column->diff( | ||
| 39 | $self->source->{columns}, $self->target->{columns}, | ||
| 40 | $self->source->{tables}, $self->target->{tables}, | ||
| 41 | 153 | ); | |
| 42 | 138 | push @ops, @column_ops; | |
| 43 | # One REORG per table the column pass leaves reorg-pending, before the first | ||
| 44 | # statement such a table refuses: a CREATE INDEX of the next pass | ||
| 45 | # (SQL0668N rc 7, karr k42). | ||
| 46 | 138 | push @ops, DBIO::DB2::Diff::Reorg->diff(@column_ops); | |
| 47 | # Index::diff also needs the tables sections to detect which tables are being | ||
| 48 | # dropped in this same pass, so it can suppress a standalone DROP INDEX that | ||
| 49 | # DROP TABLE already covers (DB2 drops a table's own indexes with it -- karr k19). | ||
| 50 | push @ops, DBIO::DB2::Diff::Index->diff( | ||
| 51 | $self->source->{indexes}, $self->target->{indexes}, | ||
| 52 | $self->source->{tables}, $self->target->{tables}, | ||
| 53 | $self->target->{columns}, $self->target->{unique_constraints}, | ||
| 54 | $self->source->{columns}, | ||
| 55 | 138 | ); | |
| 56 | # UNIQUE constraints of tables present on both sides (those of a new table are | ||
| 57 | # inline in its CREATE TABLE): after the indexes, before the FKs (karr k39, | ||
| 58 | # ADR 0009). | ||
| 59 | push @ops, DBIO::DB2::Diff::UniqueConstraint->diff( | ||
| 60 | $self->source->{unique_constraints}, $self->target->{unique_constraints}, | ||
| 61 | $self->source->{tables}, $self->target->{tables}, | ||
| 62 | $self->source->{columns}, $self->target->{columns}, | ||
| 63 | 138 | ); | |
| 64 | push @ops, DBIO::DB2::Diff::ForeignKey->diff( | ||
| 65 | $self->source->{foreign_keys}, $self->target->{foreign_keys}, | ||
| 66 | $self->source->{tables}, $self->target->{tables}, | ||
| 67 | 138 | ); | |
| 68 | 138 | push @ops, grep { $_->action eq 'create' } @view_ops; | |
| 69 | |||
| 70 | 138 | return \@ops; | |
| 71 | } | ||
| 72 | |||
| 73 | 45 | 1; | |
| 74 | |||
| 75 | __END__ | ||