165
|
1 package IMPL::SQL::Schema::Traits::Diff;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4 use IMPL::lang;
|
|
5
|
|
6 use IMPL::SQL::Schema();
|
|
7 use IMPL::SQL::Schema::Traits();
|
|
8
|
|
9 use constant {
|
|
10 schema_t => typeof IMPL::SQL::Schema # defining a constant is a good style to enable compile checks
|
|
11 };
|
|
12
|
|
13 sub Diff {
|
|
14 my ($self,$src,$dst) = @_;
|
|
15
|
|
16 die new IMPL::InvalidArgumentException( src => "A valid source schema is required") unless is($src,schema_t);
|
|
17 die new IMPL::InvalidArgumentException( dst => "A valid desctination schema is requried" ) unless is($src,schema_t);
|
|
18
|
|
19 my %dstTables = map { $_->name, $_ } $dst->GetTables;
|
|
20
|
|
21 my @operations;
|
|
22
|
|
23 foreach my $srcTable ( $src->GetTables) {
|
|
24 my $dstTable = delete $dstTables{$srcTable->name};
|
|
25
|
|
26 if (not $dstTable) {
|
|
27 push @operations, new IMPL::SQL::Schema::Traits::DropTable()
|
|
28 } else {
|
|
29
|
|
30 }
|
|
31
|
|
32 }
|
|
33 }
|
|
34
|
|
35 1; |