annotate _test/Test/SQL/Diff.pm @ 418:3f38dabaf5cc ref20150831

sync
author cin
date Mon, 28 Dec 2015 15:11:35 +0300
parents 8d36073411b1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
1 package Test::SQL::Diff;
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
2 use strict;
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
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
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
15
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
16 use IMPL::Test qw(test failed assert);
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
17 use IMPL::SQL::Types qw(Integer Varchar Text);
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
18 use Data::Dumper;
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
19
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
20
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
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
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
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
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
25
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
26 my $users = $schemaDst->AddTable({
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
27 name => 'User',
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
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
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
30 { name => 'login', type => Varchar(255) },
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
31 { name => 'description', type => Text, isNullable => 1 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
32 ]
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
33 });
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
34
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
35 $users->SetPrimaryKey('id');
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
36 $users->AddConstraint( unique => { name => 'unique_login', columns => ['login'] } );
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
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
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
55 $schemaSrc->Dispose;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
56 $schemaDst->Dispose;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
57
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
58 };
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
59
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents:
diff changeset
60
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 169
diff changeset
61 1;