168
|
1 package Test::SQL::Diff;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4 use parent qw(IMPL::Test::Unit);
|
|
5
|
|
6 use IMPL::Test qw(test failed assert);
|
|
7 use IMPL::SQL::Schema();
|
|
8 use IMPL::SQL::Types qw(Integer Varchar Text);
|
|
9 use IMPL::SQL::Schema::Traits::Diff();
|
|
10 use Data::Dumper;
|
|
11
|
|
12 __PACKAGE__->PassThroughArgs;
|
|
13
|
|
14 test diff => sub {
|
194
|
15 my $schemaSrc = new IMPL::SQL::Schema(name => 'simple', version => 1 );
|
|
16
|
|
17 my $tbl = $schemaSrc->AddTable({
|
|
18 name => 'User',
|
|
19 columns => [
|
|
20 { name => 'name', type => Varchar(255) },
|
|
21 { name => 'description', type => Varchar(255) }
|
|
22 ]
|
|
23 });
|
|
24
|
|
25 $tbl->AddConstraint( unique => { name => 'unique_name', columns => ['name'] });
|
|
26
|
|
27 my $schemaDst = new IMPL::SQL::Schema(name => 'simple', version => 2 );
|
|
28
|
|
29 my $users = $schemaDst->AddTable({
|
|
30 name => 'User',
|
|
31 columns => [
|
|
32 { name => 'id', type => Integer },
|
|
33 { name => 'login', type => Varchar(255) },
|
|
34 { name => 'description', type => Text, isNullable => 1 }
|
|
35 ]
|
|
36 });
|
|
37
|
|
38 $users->SetPrimaryKey('id');
|
|
39 $users->AddConstraint( unique => { name => 'unique_login', columns => ['login'] } );
|
|
40
|
|
41 #warn Dumper(IMPL::SQL::Schema::Traits::Diff->Diff($schemaSrc,$schemaDst));
|
|
42
|
|
43 $schemaSrc->Dispose;
|
|
44 $schemaDst->Dispose;
|
|
45
|
168
|
46 };
|
|
47
|
|
48
|
180
|
49 1;
|