5 # Note that the bulk of the testing for the mysql producer is in
6 # 08postgres-to-mysql.t. This test is for additional stuff that can't be tested
7 # using an Oracle schema as source e.g. extra attributes.
13 use Test::SQL::Translator qw(maybe_plan);
19 #=============================================================================
24 'SQL::Translator::Producer::MySQL',
28 use Test::Differences;
33 my $yaml_in = <<EOSCHEMA;
41 mysql_collate: latin1_danish_ci
46 data_type: unsigned int
68 mysql_collate: utf8_general_ci
91 - reference_table: thing
98 my $mysql_out = <<EOSQL;
99 SET foreign_key_checks=0;
102 id unsigned int auto_increment,
104 swedish_name varchar(32) CHARACTER SET swe7,
105 description text CHARACTER SET utf8 COLLATE utf8_general_ci,
108 ) Type=InnoDB DEFAULT CHARACTER SET latin1 COLLATE latin1_danish_ci;
110 CREATE TABLE thing2 (
115 PRIMARY KEY (id, foo),
116 CONSTRAINT thing2_fk_thing FOREIGN KEY (foo) REFERENCES thing (id)
119 SET foreign_key_checks=1;
124 $sqlt = SQL::Translator->new(
132 my $out = $sqlt->translate(\$yaml_in)
133 or die "Translate error:".$sqlt->error;
134 ok $out ne "" ,"Produced something!";
135 eq_or_diff $out, $mysql_out ,"Output looks right";
138 ###############################################################################
141 my $table = SQL::Translator::Schema::Table->new( name => 'mytable');
143 my $field1 = SQL::Translator::Schema::Field->new( name => 'myfield',
145 data_type => 'VARCHAR',
147 default_value => undef,
148 is_auto_increment => 0,
153 my $field1_sql = SQL::Translator::Producer::MySQL::create_field($field1);
155 is($field1_sql, 'myfield VARCHAR(10)', 'Create field works');
157 my $field2 = SQL::Translator::Schema::Field->new( name => 'myfield',
159 data_type => 'VARCHAR',
161 default_value => undef,
162 is_auto_increment => 0,
167 my $alter_field = SQL::Translator::Producer::MySQL::alter_field($field1,
169 is($alter_field, 'ALTER TABLE mytable CHANGE COLUMN myfield myfield VARCHAR(25) NOT NULL', 'Alter field works');
171 my $add_field = SQL::Translator::Producer::MySQL::add_field($field1);
173 is($add_field, 'ALTER TABLE mytable ADD COLUMN myfield VARCHAR(10)', 'Add field works');
175 my $drop_field = SQL::Translator::Producer::MySQL::drop_field($field2);
176 is($drop_field, 'ALTER TABLE mytable DROP COLUMN myfield', 'Drop field works');