diff _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
line wrap: on
line diff
--- a/_test/Test/SQL/Diff.pm	Fri Jan 25 00:25:02 2013 +0400
+++ b/_test/Test/SQL/Diff.pm	Mon Jan 28 02:43:14 2013 +0400
@@ -1,35 +1,32 @@
 package Test::SQL::Diff;
 use strict;
 use warnings;
-use parent qw(IMPL::Test::Unit);
+
+use IMPL::declare {
+    require => {
+        MySQLProcessor => 'IMPL::SQL::Schema::MySQL::Processor',
+        SQLSchema => 'IMPL::SQL::Schema',
+        SQLDiff => 'IMPL::SQL::Schema::Diff'
+    },
+    base => [
+        'IMPL::Test::Unit' => '@_'
+    ]    
+};
 
 use IMPL::Test qw(test failed assert);
-use IMPL::SQL::Schema();
 use IMPL::SQL::Types qw(Integer Varchar Text);
-use IMPL::SQL::Schema::Traits::Diff();
 use Data::Dumper;
 
-__PACKAGE__->PassThroughArgs;
 
 test diff => sub {
-    my $schemaSrc = new IMPL::SQL::Schema(name => 'simple', version => 1 );
+    my $schemaSrc = SQLSchema->new(name => 'simple', version => 1 );
     
-    my $tbl = $schemaSrc->AddTable({
-        name => 'User',
-        columns => [
-            { name => 'name', type => Varchar(255) },
-            { name => 'description', type => Varchar(255) }
-        ]
-    });
-    
-    $tbl->AddConstraint( unique => { name => 'unique_name', columns => ['name'] });
-    
-    my $schemaDst = new IMPL::SQL::Schema(name => 'simple', version => 2 );
+    my $schemaDst = SQLSchema->new(name => 'simple', version => 2 );
     
     my $users = $schemaDst->AddTable({
         name => 'User',
         columns => [
-            { name => 'id', type => Integer },
+            { name => 'id', type => Integer, tag => {auto_increment => 1} },
             { name => 'login', type => Varchar(255) },
             { name => 'description', type => Text, isNullable => 1 }
         ]
@@ -38,7 +35,25 @@
     $users->SetPrimaryKey('id');
     $users->AddConstraint( unique => { name => 'unique_login', columns => ['login'] } );
     
-    #warn Dumper(IMPL::SQL::Schema::Traits::Diff->Diff($schemaSrc,$schemaDst));
+    my $profile = $schemaDst->AddTable({
+        name => 'Profile',
+        columns => [
+            { name => 'id', type => Integer, tag => {auto_increment => 1} },
+            { name => 'uid', type => Integer },
+            { name => 'data', type => Text }
+        ]
+    });
+    
+    $profile->SetPrimaryKey('id');
+    $profile->LinkTo($users, 'uid');
+    
+    my $diff = SQLDiff->Diff($schemaSrc,$schemaDst);
+    
+    my $processor = MySQLProcessor->new($schemaSrc);
+    $processor->ProcessBatch($diff);
+    
+    warn Dumper($diff);
+    warn Dumper($processor->sqlBatch);
     
     $schemaSrc->Dispose;
     $schemaDst->Dispose;