8 use File::Spec::Functions qw(catfile updir tmpdir);
11 use Test::Differences;
12 use Test::SQL::Translator qw(maybe_plan);
16 use_ok('SQL::Translator::Diff') or die "Cannot continue\n";
18 my $tr = SQL::Translator->new;
20 my ( $source_schema, $target_schema ) = map {
21 my $t = SQL::Translator->new;
24 my $out = $t->translate( catfile($Bin, qw/data diff/, $_ ) )
27 my $schema = $t->schema;
28 unless ( $schema->name ) {
32 } (qw/create1.yml create2.yml/);
34 # Test for differences
35 my $out = SQL::Translator::Diff::schema_diff( $source_schema, 'SQLite', $target_schema, 'SQLite',
36 { no_batch_alters => 1,
37 ignore_missing_methods => 1,
38 output_db => 'SQLite',
41 eq_or_diff($out, <<'## END OF DIFF', "Diff as expected");
42 -- Convert schema 'create1.yml' to 'create2.yml':
51 DROP INDEX FK5302D47D93FE702E ON employee;
52 DROP INDEX UC_age_name ON person;
53 DROP INDEX u_name ON person;
54 -- SQL::Translator::Producer::SQLite cant drop_field
55 ALTER TABLE person ADD COLUMN is_rock_star tinyint(4) DEFAULT '1';
56 -- SQL::Translator::Producer::SQLite cant alter_field
57 -- SQL::Translator::Producer::SQLite cant rename_field
58 CREATE UNIQUE INDEX unique_name_person ON person (name);
59 CREATE UNIQUE INDEX UC_person_id_person ON person (person_id);
60 CREATE UNIQUE INDEX UC_age_name_person ON person (age, name);
67 $out = SQL::Translator::Diff::schema_diff($source_schema, 'SQLite', $target_schema, 'SQLite',
68 { ignore_index_names => 1,
69 ignore_constraint_names => 1,
70 output_db => 'SQLite',
73 eq_or_diff($out, <<'## END OF DIFF', "Diff as expected");
74 -- Convert schema 'create1.yml' to 'create2.yml':
84 CREATE TEMPORARY TABLE employee_temp_alter (
85 position varchar(50) NOT NULL,
86 employee_id int(11) NOT NULL,
87 PRIMARY KEY (position, employee_id)
89 INSERT INTO employee_temp_alter SELECT position, employee_id FROM employee;
91 CREATE TABLE employee (
92 position varchar(50) NOT NULL,
93 employee_id int(11) NOT NULL,
94 PRIMARY KEY (position, employee_id)
96 INSERT INTO employee SELECT position, employee_id FROM employee_temp_alter;
97 DROP TABLE employee_temp_alter;
99 CREATE TEMPORARY TABLE person_temp_alter (
100 person_id INTEGER PRIMARY KEY NOT NULL,
101 name varchar(20) NOT NULL,
102 age int(11) DEFAULT '18',
104 iq int(11) DEFAULT '0',
105 is_rock_star tinyint(4) DEFAULT '1',
106 physical_description text
108 INSERT INTO person_temp_alter SELECT person_id, name, age, weight, iq, is_rock_star, physical_description FROM person;
110 CREATE TABLE person (
111 person_id INTEGER PRIMARY KEY NOT NULL,
112 name varchar(20) NOT NULL,
113 age int(11) DEFAULT '18',
115 iq int(11) DEFAULT '0',
116 is_rock_star tinyint(4) DEFAULT '1',
117 physical_description text
119 CREATE UNIQUE INDEX unique_name_person02 ON person (name);
120 CREATE UNIQUE INDEX UC_person_id_person02 ON person (person_id);
121 CREATE UNIQUE INDEX UC_age_name_person02 ON person (age, name);
122 INSERT INTO person SELECT person_id, name, age, weight, iq, is_rock_star, physical_description FROM person_temp_alter;
123 DROP TABLE person_temp_alter;
132 $out = SQL::Translator::Diff::schema_diff($source_schema, 'MySQL', $source_schema, 'MySQL' );
134 eq_or_diff($out, <<'## END OF DIFF', "No differences found");
135 -- Convert schema 'create1.yml' to 'create1.yml':
137 -- No differences found