Mercurial > pub > Impl
annotate _test/Test/SQL/Diff.pm @ 271:56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
author | cin |
---|---|
date | Mon, 28 Jan 2013 02:43:14 +0400 |
parents | 4d0e1962161c |
children | 8d36073411b1 |
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 |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
55 warn Dumper($diff); |
56364d0c4b4f
+IMPL::SQL::Schema::MySQL: added basic support for MySQL
cin
parents:
194
diff
changeset
|
56 warn Dumper($processor->sqlBatch); |
194 | 57 |
58 $schemaSrc->Dispose; | |
59 $schemaDst->Dispose; | |
60 | |
168 | 61 }; |
62 | |
63 | |
180 | 64 1; |