Add renamed_from to tables.
[dbsrgits/SQL-Translator.git] / t / 30sqlt-diff.t
CommitLineData
034bdbe4 1#!/usr/bin/perl
2# vim: set ft=perl:
3
4use strict;
5
6use File::Spec::Functions qw(catfile updir tmpdir);
7use FindBin qw($Bin);
8use Test::More;
9use Test::SQL::Translator qw(maybe_plan);
10
da5a1bae 11my @script = qw(blib script sqlt-diff-old);
034bdbe4 12my @create1 = qw(data sqlite create.sql);
13my @create2 = qw(data sqlite create2.sql);
14
15my $sqlt_diff = (-d "blib")
16 ? catfile($Bin, updir, @script)
17 : catfile($Bin, @script);
18
19my $create1 = (-d "t")
20 ? catfile($Bin, @create1)
21 : catfile($Bin, "t", @create1);
22
23my $create2 = (-d "t")
24 ? catfile($Bin, @create2)
25 : catfile($Bin, "t", @create2);
26
27BEGIN {
da5a1bae 28 maybe_plan(21,
034bdbe4 29 'SQL::Translator::Parser::SQLite',
fb3e4caf 30 'SQL::Translator::Parser::MySQL',
32d8b258 31 'SQL::Translator::Parser::Oracle',
034bdbe4 32 );
33}
34
35ok(-e $sqlt_diff, 'Found sqlt-diff script');
36my @cmd = ($sqlt_diff, "$create1=SQLite", "$create2=SQLite");
034bdbe4 37my $out = `@cmd`;
38
bf459ae6 39like($out, qr/-- Target database SQLite is untested/, "Detected 'untested' comment");
034bdbe4 40like($out, qr/ALTER TABLE person CHANGE iq/, "Detected altered 'iq' field");
41like($out, qr/ALTER TABLE person ADD is_rock_star/,
42 "Detected missing rock star field");
fb3e4caf 43
44@cmd = ($sqlt_diff, "$create1=SQLite", "$create1=SQLite");
45$out = `@cmd`;
46
da5a1bae 47like($out, qr/There were no differences/, "Properly detected no differences");
fb3e4caf 48
49my @mysql_create1 = qw(data mysql create.sql);
50my @mysql_create2 = qw(data mysql create2.sql);
51
52my $mysql_create1 = (-d "t")
53 ? catfile($Bin, @mysql_create1)
54 : catfile($Bin, "t", @mysql_create1);
55
56my $mysql_create2 = (-d "t")
57 ? catfile($Bin, @mysql_create2)
58 : catfile($Bin, "t", @mysql_create2);
59
d990d84b 60# Test for differences
fb3e4caf 61@cmd = ($sqlt_diff, "$mysql_create1=MySQL", "$mysql_create2=MySQL");
62$out = `@cmd`;
63
bf459ae6 64unlike($out, qr/-- Target database MySQL is untested/, "Did not detect 'untested' comment");
fb3e4caf 65like($out, qr/ALTER TABLE person CHANGE person_id/, "Detected altered 'person_id' field");
66like($out, qr/ALTER TABLE person CHANGE iq/, "Detected altered 'iq' field");
67like($out, qr/ALTER TABLE person CHANGE name/, "Detected altered 'name' field");
68like($out, qr/ALTER TABLE person CHANGE age/, "Detected altered 'age' field");
69like($out, qr/ALTER TABLE person ADD is_rock_star/,
70 "Detected missing rock star field");
71like($out, qr/ALTER TABLE person ADD UNIQUE UC_person_id/,
72 "Detected missing unique constraint");
d990d84b 73like($out, qr/CREATE UNIQUE INDEX unique_name/,
74 "Detected unique index with different name");
fb3e4caf 75like($out, qr/ALTER TABLE person ENGINE=InnoDB;/,
76 "Detected altered table option");
d990d84b 77like($out, qr/ALTER TABLE employee DROP FOREIGN KEY FK5302D47D93FE702E/,
9ae898b9 78 "Detected drop foreign key");
d990d84b 79like($out, qr/ALTER TABLE employee ADD CONSTRAINT FK5302D47D93FE702E_diff/,
9ae898b9 80 "Detected add constraint");
6a0f3000 81unlike($out, qr/ALTER TABLE employee ADD PRIMARY KEY/, "Primary key looks different when it shouldn't");
d990d84b 82
d990d84b 83# Test for sameness
fb3e4caf 84@cmd = ($sqlt_diff, "$mysql_create1=MySQL", "$mysql_create1=MySQL");
85$out = `@cmd`;
86
da5a1bae 87like($out, qr/There were no differences/, "Properly detected no differences");
32d8b258 88
89my @oracle_create1 = qw(data oracle create.sql);
90my @oracle_create2 = qw(data oracle create2.sql);
91
92my $oracle_create1 = (-d "t")
93 ? catfile($Bin, @oracle_create1)
94 : catfile($Bin, "t", @oracle_create1);
95
96my $oracle_create2 = (-d "t")
97 ? catfile($Bin, @oracle_create2)
98 : catfile($Bin, "t", @oracle_create2);
99
100@cmd = ($sqlt_diff, "$oracle_create1=Oracle", "$oracle_create2=Oracle");
101$out = `@cmd`;
102
bf459ae6 103unlike($out, qr/-- Target database Oracle is untested/, "Did not detect 'untested' comment");
32d8b258 104like($out, qr/ALTER TABLE TABLE1 DROP FOREIGN KEY/,
105 "Detected drop foreign key");
106like($out, qr/ALTER TABLE TABLE1 ADD CONSTRAINT/,
107 "Detected add constraint");