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