introspect ON DELETE/UPDATE clauses for MySQL FKs
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 10_02mysql_common.t
index bc457cd..948d2c4 100644 (file)
@@ -180,10 +180,24 @@ my $tester = dbixcsl_common_tests->new(
                   PRIMARY KEY (`ISO3_code`)
                 ) $innodb
             },
+            # 4 through 10 are used for the multi-schema tests
+            qq{
+                create table mysql_loader_test11 (
+                    id int auto_increment primary key
+                ) $innodb
+            },
+            qq{
+                create table mysql_loader_test12 (
+                    id int auto_increment primary key,
+                    eleven_id int,
+                    foreign key (eleven_id) references mysql_loader_test11(id)
+                        on delete restrict on update set null
+                ) $innodb
+            },
         ],
         pre_drop_ddl => [ 'DROP VIEW mysql_loader_test2', ],
-        drop => [ 'mysql_loader-test1', 'mysql_loader_test3' ],
-        count => 5 + 30 * 2,
+        drop => [ 'mysql_loader-test1', 'mysql_loader_test3', 'mysql_loader_test11', 'mysql_loader_test12' ],
+        count => 8 + 30 * 2,
         run => sub {
             my ($monikers, $classes);
             ($schema, $monikers, $classes) = @_;
@@ -212,6 +226,17 @@ my $tester = dbixcsl_common_tests->new(
             like $code, qr/^=head2 id\n\n(.+:.+\n)+\nThe\nColumn\n\n/m,
                 'column comment and attrs';
 
+            # test on delete/update fk clause introspection
+            ok ((my $rel_info = $schema->source('MysqlLoaderTest12')->relationship_info('eleven')),
+                'got rel info');
+
+            is $rel_info->{attrs}{on_delete}, 'RESTRICT',
+                'ON DELETE clause introspected correctly';
+
+            is $rel_info->{attrs}{on_update}, 'SET NULL',
+                'ON UPDATE clause introspected correctly';
+
+            # multischema tests follow
             SKIP: {
                 my $dbh = $schema->storage->dbh;
 
@@ -219,6 +244,7 @@ my $tester = dbixcsl_common_tests->new(
                     $dbh->do('CREATE DATABASE `dbicsl-test`');
                 }
                 catch {
+                    diag "CREATE DATABASE returned error: '$_'";
                     skip "no CREATE DATABASE privileges", 30 * 2;
                 };
 
@@ -319,7 +345,6 @@ EOF
                             {
                                 naming => 'current',
                                 db_schema => $db_schema,
-                                moniker_parts => ['schema', 'name'],
                                 dump_directory => EXTRA_DUMP_DIR,
                                 quiet => 1,
                             },
@@ -338,7 +363,7 @@ EOF
                     } 'connected test schema';
 
                     lives_and {
-                        ok $rsrc = $test_schema->source('DbicslDashTestMysqlLoaderTest4');
+                        ok $rsrc = $test_schema->source('MysqlLoaderTest4');
                     } 'got source for table in database name with dash';
 
                     is try { $rsrc->column_info('id')->{is_auto_increment} }, 1,
@@ -351,7 +376,7 @@ EOF
                         'column in database name with dash';
 
                     lives_and {
-                        ok $rs = $test_schema->resultset('DbicslDashTestMysqlLoaderTest4');
+                        ok $rs = $test_schema->resultset('MysqlLoaderTest4');
                     } 'got resultset for table in database name with dash';
 
                     lives_and {
@@ -389,7 +414,7 @@ EOF
                         'unique constraint is correct in database name with dash');
 
                     lives_and {
-                        ok $rsrc = $test_schema->source('DbicslDotTestMysqlLoaderTest6');
+                        ok $rsrc = $test_schema->source('MysqlLoaderTest6');
                     } 'got source for table in database name with dot';
 
                     is try { $rsrc->column_info('id')->{is_auto_increment} }, 1,
@@ -402,7 +427,7 @@ EOF
                         'column in database name with dot introspected correctly';
 
                     lives_and {
-                        ok $rs = $test_schema->resultset('DbicslDotTestMysqlLoaderTest6');
+                        ok $rs = $test_schema->resultset('MysqlLoaderTest6');
                     } 'got resultset for table in database name with dot';
 
                     lives_and {
@@ -426,7 +451,7 @@ EOF
                     }
 
                     lives_and {
-                        ok $rsrc = $test_schema->source('DbicslDotTestMysqlLoaderTest7');
+                        ok $rsrc = $test_schema->source('MysqlLoaderTest7');
                     } 'got source for table in database name with dot';
 
                     %uniqs = try { $rsrc->unique_constraints };
@@ -443,22 +468,22 @@ EOF
                         skip 'set the environment variable DBICTEST_MYSQL_INNODB=1 to test relationships', 4 unless $test_innodb;
 
                         lives_and {
-                            ok $test_schema->source('DbicslDotTestMysqlLoaderTest6')
+                            ok $test_schema->source('MysqlLoaderTest6')
                                 ->has_relationship('mysql_loader_test4');
                         } 'cross-database relationship in multi-db_schema';
 
                         lives_and {
-                            ok $test_schema->source('DbicslDashTestMysqlLoaderTest4')
+                            ok $test_schema->source('MysqlLoaderTest4')
                                 ->has_relationship('mysql_loader_test6s');
                         } 'cross-database relationship in multi-db_schema';
 
                         lives_and {
-                            ok $test_schema->source('DbicslDashTestMysqlLoaderTest8')
+                            ok $test_schema->source('MysqlLoaderTest8')
                                 ->has_relationship('mysql_loader_test7');
                         } 'cross-database relationship in multi-db_schema';
 
                         lives_and {
-                            ok $test_schema->source('DbicslDotTestMysqlLoaderTest7')
+                            ok $test_schema->source('MysqlLoaderTest7')
                                 ->has_relationship('mysql_loader_test8s');
                         } 'cross-database relationship in multi-db_schema';
                     }