Commit | Line | Data |
034bdbe4 |
1 | #!/usr/bin/perl |
2 | # vim: set ft=perl: |
3 | |
4 | use strict; |
5 | |
6 | use File::Spec::Functions qw(catfile updir tmpdir); |
7 | use FindBin qw($Bin); |
8 | use Test::More; |
9 | use Test::SQL::Translator qw(maybe_plan); |
10 | |
da5a1bae |
11 | my @script = qw(blib script sqlt-diff-old); |
034bdbe4 |
12 | my @create1 = qw(data sqlite create.sql); |
13 | my @create2 = qw(data sqlite create2.sql); |
14 | |
15 | my $sqlt_diff = (-d "blib") |
16 | ? catfile($Bin, updir, @script) |
17 | : catfile($Bin, @script); |
18 | |
19 | my $create1 = (-d "t") |
20 | ? catfile($Bin, @create1) |
21 | : catfile($Bin, "t", @create1); |
22 | |
23 | my $create2 = (-d "t") |
24 | ? catfile($Bin, @create2) |
25 | : catfile($Bin, "t", @create2); |
26 | |
27 | BEGIN { |
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 | |
35 | ok(-e $sqlt_diff, 'Found sqlt-diff script'); |
36 | my @cmd = ($sqlt_diff, "$create1=SQLite", "$create2=SQLite"); |
034bdbe4 |
37 | my $out = `@cmd`; |
38 | |
bf459ae6 |
39 | like($out, qr/-- Target database SQLite is untested/, "Detected 'untested' comment"); |
034bdbe4 |
40 | like($out, qr/ALTER TABLE person CHANGE iq/, "Detected altered 'iq' field"); |
41 | like($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 |
47 | like($out, qr/There were no differences/, "Properly detected no differences"); |
fb3e4caf |
48 | |
49 | my @mysql_create1 = qw(data mysql create.sql); |
50 | my @mysql_create2 = qw(data mysql create2.sql); |
51 | |
52 | my $mysql_create1 = (-d "t") |
53 | ? catfile($Bin, @mysql_create1) |
54 | : catfile($Bin, "t", @mysql_create1); |
55 | |
56 | my $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 |
64 | unlike($out, qr/-- Target database MySQL is untested/, "Did not detect 'untested' comment"); |
fb3e4caf |
65 | like($out, qr/ALTER TABLE person CHANGE person_id/, "Detected altered 'person_id' field"); |
66 | like($out, qr/ALTER TABLE person CHANGE iq/, "Detected altered 'iq' field"); |
67 | like($out, qr/ALTER TABLE person CHANGE name/, "Detected altered 'name' field"); |
68 | like($out, qr/ALTER TABLE person CHANGE age/, "Detected altered 'age' field"); |
69 | like($out, qr/ALTER TABLE person ADD is_rock_star/, |
70 | "Detected missing rock star field"); |
71 | like($out, qr/ALTER TABLE person ADD UNIQUE UC_person_id/, |
72 | "Detected missing unique constraint"); |
d990d84b |
73 | like($out, qr/CREATE UNIQUE INDEX unique_name/, |
74 | "Detected unique index with different name"); |
fb3e4caf |
75 | like($out, qr/ALTER TABLE person ENGINE=InnoDB;/, |
76 | "Detected altered table option"); |
d990d84b |
77 | like($out, qr/ALTER TABLE employee DROP FOREIGN KEY FK5302D47D93FE702E/, |
9ae898b9 |
78 | "Detected drop foreign key"); |
d990d84b |
79 | like($out, qr/ALTER TABLE employee ADD CONSTRAINT FK5302D47D93FE702E_diff/, |
9ae898b9 |
80 | "Detected add constraint"); |
6a0f3000 |
81 | unlike($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 |
87 | like($out, qr/There were no differences/, "Properly detected no differences"); |
32d8b258 |
88 | |
89 | my @oracle_create1 = qw(data oracle create.sql); |
90 | my @oracle_create2 = qw(data oracle create2.sql); |
91 | |
92 | my $oracle_create1 = (-d "t") |
93 | ? catfile($Bin, @oracle_create1) |
94 | : catfile($Bin, "t", @oracle_create1); |
95 | |
96 | my $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 |
103 | unlike($out, qr/-- Target database Oracle is untested/, "Did not detect 'untested' comment"); |
32d8b258 |
104 | like($out, qr/ALTER TABLE TABLE1 DROP FOREIGN KEY/, |
105 | "Detected drop foreign key"); |
106 | like($out, qr/ALTER TABLE TABLE1 ADD CONSTRAINT/, |
107 | "Detected add constraint"); |