| 1 | package DBIO::DB2::Diff; | ||
| 2 | # ABSTRACT: Compare two introspected DB2 models | ||
| 3 | |||
| 4 | 4 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 4 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 4 | ▶ | use base 'DBIO::Diff::Base'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 4 | ▶ | use DBIO::DB2::Diff::Table; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 4 | ▶ | use DBIO::DB2::Diff::Column; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 4 | ▶ | use DBIO::DB2::Diff::Index; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 4 | ▶ | use DBIO::DB2::Diff::ForeignKey; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | |||
| 14 | |||
| 15 | 6 | ▶ | sub _build_operations { |
|
Subroutine
_build_operations: called CC=1 SCAR=0.0
| |||
| 16 | 6 | my ($self) = @_; | |
| 17 | 6 | my @ops; | |
| 18 | |||
| 19 | push @ops, DBIO::DB2::Diff::Table->diff( | ||
| 20 | $self->source->{tables}, $self->target->{tables}, | ||
| 21 | $self->target->{columns}, $self->target->{foreign_keys}, | ||
| 22 | 6 | ); | |
| 23 | push @ops, DBIO::DB2::Diff::Column->diff( | ||
| 24 | $self->source->{columns}, $self->target->{columns}, | ||
| 25 | $self->source->{tables}, $self->target->{tables}, | ||
| 26 | 6 | ); | |
| 27 | # Index::diff also needs the tables sections to detect which tables are being | ||
| 28 | # dropped in this same pass, so it can suppress a standalone DROP INDEX that | ||
| 29 | # DROP TABLE already covers (DB2 drops a table's own indexes with it -- karr #19). | ||
| 30 | push @ops, DBIO::DB2::Diff::Index->diff( | ||
| 31 | $self->source->{indexes}, $self->target->{indexes}, | ||
| 32 | $self->source->{tables}, $self->target->{tables}, | ||
| 33 | 6 | ); | |
| 34 | push @ops, DBIO::DB2::Diff::ForeignKey->diff( | ||
| 35 | $self->source->{foreign_keys}, $self->target->{foreign_keys}, | ||
| 36 | $self->source->{tables}, $self->target->{tables}, | ||
| 37 | 6 | ); | |
| 38 | |||
| 39 | 6 | return \@ops; | |
| 40 | } | ||
| 41 | |||
| 42 | 4 | 1; | |
| 43 | |||
| 44 | __END__ | ||
| 45 | |||
| 46 | =pod | ||
| 47 | |||
| 48 | =encoding UTF-8 | ||
| 49 | |||
| 50 | =head1 NAME | ||
| 51 | |||
| 52 | DBIO::DB2::Diff - Compare two introspected DB2 models | ||
| 53 | |||
| 54 | =head1 VERSION | ||
| 55 | |||
| 56 | version 0.900001 | ||
| 57 | |||
| 58 | =head1 DESCRIPTION | ||
| 59 | |||
| 60 | C<DBIO::DB2::Diff> compares two introspected DB2 models (produced | ||
| 61 | by L<DBIO::DB2::Introspect>) and emits a list of structured diff | ||
| 62 | operations that can be rendered to SQL or a human-readable summary. | ||
| 63 | |||
| 64 | my $diff = DBIO::DB2::Diff->new( | ||
| 65 | source => $current_model, | ||
| 66 | target => $desired_model, | ||
| 67 | ); | ||
| 68 | |||
| 69 | if ($diff->has_changes) { | ||
| 70 | print $diff->as_sql; | ||
| 71 | print $diff->summary; | ||
| 72 | } | ||
| 73 | |||
| 74 | Operations are emitted in dependency order: tables, then columns, then | ||
| 75 | indexes, then foreign keys. New-table FKs are created inline by | ||
| 76 | L<DBIO::DB2::Diff::Table>; L<DBIO::DB2::Diff::ForeignKey> handles FK changes | ||
| 77 | on tables present in both models. FKs come last so any referenced table or | ||
| 78 | column already exists. Drops come last for each layer. | ||
| 79 | |||
| 80 | =head1 AUTHOR | ||
| 81 | |||
| 82 | DBIO & DBIx::Class Authors | ||
| 83 | |||
| 84 | =head1 COPYRIGHT AND LICENSE | ||
| 85 | |||
| 86 | Copyright (C) 2026 DBIO Authors | ||
| 87 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||
| 88 | Based on DBIx::Class, heavily modified. | ||
| 89 | |||
| 90 | This is free software; you can redistribute it and/or modify it under | ||
| 91 | the same terms as the Perl 5 programming language system itself. | ||
| 92 | |||
| 93 | =cut | ||