auto-disambiguate monikers from different schemas
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 10_08sqlanywhere_common.t
index f52bc4e..a626b86 100644 (file)
@@ -144,7 +144,7 @@ my $tester = dbixcsl_common_tests->new(
         'ntext'        => { data_type => 'ntext' },
     },
     extra => {
-        count => 28 * 2,
+        count => 30 * 2,
         run => sub {
             SKIP: {
                 $schema  = $_[0];
@@ -159,7 +159,7 @@ my $tester = dbixcsl_common_tests->new(
                 }
                 catch {
                     $schemas_created = 0;
-                    skip "no CREATE USER privileges", 28 * 2;
+                    skip "no CREATE USER privileges", 30 * 2;
                 };
 
                 $dbh->do(<<"EOF");
@@ -172,12 +172,22 @@ EOF
                     CREATE TABLE dbicsl_test1.sqlanywhere_loader_test5 (
                         id INT IDENTITY NOT NULL PRIMARY KEY,
                         value VARCHAR(100),
-                        four_id INTEGER NOT NULL UNIQUE,
+                        four_id INTEGER NOT NULL,
+                        CONSTRAINT loader_test5_uniq UNIQUE (four_id),
                         FOREIGN KEY (four_id) REFERENCES dbicsl_test1.sqlanywhere_loader_test4 (id)
                     )
 EOF
                 $dbh->do("CREATE USER dbicsl_test2 identified by 'dbicsl'");
                 $dbh->do(<<"EOF");
+                    CREATE TABLE dbicsl_test2.sqlanywhere_loader_test5 (
+                        pk INT IDENTITY NOT NULL PRIMARY KEY,
+                        value VARCHAR(100),
+                        four_id INTEGER NOT NULL,
+                        CONSTRAINT loader_test5_uniq UNIQUE (four_id),
+                        FOREIGN KEY (four_id) REFERENCES dbicsl_test1.sqlanywhere_loader_test4 (id)
+                    )
+EOF
+                $dbh->do(<<"EOF");
                     CREATE TABLE dbicsl_test2.sqlanywhere_loader_test6 (
                         id INT IDENTITY NOT NULL PRIMARY KEY,
                         value VARCHAR(100),
@@ -258,7 +268,7 @@ EOF
                         ok $row = $rs->create({ value => 'foo' });
                     } 'executed SQL on table in schema one';
 
-                    $rel_info = try { $rsrc->relationship_info('sqlanywhere_loader_test5') };
+                    $rel_info = try { $rsrc->relationship_info('dbicsl_test1_sqlanywhere_loader_test5') };
 
                     is_deeply $rel_info->{cond}, {
                         'foreign.four_id' => 'self.id'
@@ -271,7 +281,7 @@ EOF
                         'relationship in schema one';
 
                     lives_and {
-                        ok $rsrc = $test_schema->source('SqlanywhereLoaderTest5');
+                        ok $rsrc = $test_schema->source('DbicslTest1SqlanywhereLoaderTest5');
                     } 'got source for table in schema one';
 
                     %uniqs = try { $rsrc->unique_constraints };
@@ -279,6 +289,11 @@ EOF
                     is keys %uniqs, 2,
                         'got unique and primary constraint in schema one';
 
+                    delete $uniqs{primary};
+
+                    is_deeply ((values %uniqs)[0], ['four_id'],
+                        'correct unique constraint in schema one');
+
                     lives_and {
                         ok $rsrc = $test_schema->source('SqlanywhereLoaderTest6');
                     } 'got source for table in schema two';
@@ -321,6 +336,11 @@ EOF
                     is keys %uniqs, 2,
                         'got unique and primary constraint in schema two';
 
+                    delete $uniqs{primary};
+
+                    is_deeply ((values %uniqs)[0], ['six_id'],
+                        'correct unique constraint in schema two');
+
                     lives_and {
                         ok $test_schema->source('SqlanywhereLoaderTest6')
                             ->has_relationship('sqlanywhere_loader_test4');
@@ -359,6 +379,7 @@ sub extra_cleanup {
             foreach my $table ('dbicsl_test1.sqlanywhere_loader_test8',
                                'dbicsl_test2.sqlanywhere_loader_test7',
                                'dbicsl_test2.sqlanywhere_loader_test6',
+                               'dbicsl_test2.sqlanywhere_loader_test5',
                                'dbicsl_test1.sqlanywhere_loader_test5',
                                'dbicsl_test1.sqlanywhere_loader_test4') {
                 try {