Mercurial > pub > Impl
annotate _test/Test/SQL/Diff.pm @ 347:3eafa6fefa9f
sync
author | cin |
---|---|
date | Mon, 30 Sep 2013 17:36:17 +0400 |
parents | 8d36073411b1 |
children |
rev | line source |
---|---|
168 | 1 package Test::SQL::Diff; |
2 use strict; | |
3 use warnings; | |
271
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
4 |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
5 use IMPL::declare { |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
6 require => { |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
7 MySQLProcessor => 'IMPL::SQL::Schema::MySQL::Processor', |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
8 SQLSchema => 'IMPL::SQL::Schema', |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
9 SQLDiff => 'IMPL::SQL::Schema::Diff' |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
10 }, |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
11 base => [ |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
12 'IMPL::Test::Unit' => '@_' |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
13 ] |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
14 }; |
168 | 15 |
16 use IMPL::Test qw(test failed assert); | |
17 use IMPL::SQL::Types qw(Integer Varchar Text); | |
18 use Data::Dumper; | |
19 | |
20 | |
21 test diff => sub { | |
271
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
22 my $schemaSrc = SQLSchema->new(name => 'simple', version => 1 ); |
194 | 23 |
271
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
24 my $schemaDst = SQLSchema->new(name => 'simple', version => 2 ); |
194 | 25 |
26 my $users = $schemaDst->AddTable({ | |
27 name => 'User', | |
28 columns => [ | |
271
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
29 { name => 'id', type => Integer, tag => {auto_increment => 1} }, |
194 | 30 { name => 'login', type => Varchar(255) }, |
31 { name => 'description', type => Text, isNullable => 1 } | |
32 ] | |
33 }); | |
34 | |
35 $users->SetPrimaryKey('id'); | |
36 $users->AddConstraint( unique => { name => 'unique_login', columns => ['login'] } ); | |
37 | |
271
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
38 my $profile = $schemaDst->AddTable({ |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
39 name => 'Profile', |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
40 columns => [ |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
41 { name => 'id', type => Integer, tag => {auto_increment => 1} }, |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
42 { name => 'uid', type => Integer }, |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
43 { name => 'data', type => Text } |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
44 ] |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
45 }); |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
46 |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
47 $profile->SetPrimaryKey('id'); |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
48 $profile->LinkTo($users, 'uid'); |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
49 |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
50 my $diff = SQLDiff->Diff($schemaSrc,$schemaDst); |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
51 |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
52 my $processor = MySQLProcessor->new($schemaSrc); |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
53 $processor->ProcessBatch($diff); |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
54 |
194 | 55 $schemaSrc->Dispose; |
56 $schemaDst->Dispose; | |
57 | |
168 | 58 }; |
59 | |
60 | |
180 | 61 1; |