Added constraint copy to Globals filter. (Seem to be getting lots of warnings from...
[dbsrgits/SQL-Translator.git] / t / 38-mysql-producer.t
1 #!/usr/bin/perl -w
2 # vim:filetype=perl
3
4 #
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.
8 #
9
10 use strict;
11 use Test::More;
12 use Test::Exception;
13 use Test::SQL::Translator qw(maybe_plan);
14
15 use Data::Dumper;
16 use FindBin qw/$Bin/;
17
18 # Testing 1,2,3,4...
19 #=============================================================================
20
21 BEGIN {
22     maybe_plan(2,
23         'YAML',
24         'SQL::Translator::Producer::MySQL',
25         'Test::Differences',
26     )
27 }
28 use Test::Differences;
29 use SQL::Translator;
30
31 # Main test.
32 {
33 my $yaml_in = <<EOSCHEMA;
34 ---
35 schema:
36   tables:
37     thing:
38       name: thing
39       extra:
40         mysql_table_type: InnoDB
41         mysql_charset: latin1 
42         mysql_collate: latin1_danish_ci 
43       order: 1
44       fields:
45         name:
46           name: name
47           data_type: varchar
48           size:
49             - 32
50           order: 1
51         swedish_name:
52           name: swedish_name
53           data_type: varchar
54           size: 32
55           extra:
56             mysql_charset: swe7
57           order: 2
58         description:
59           name: description
60           data_type: text
61           extra:
62             mysql_charset: utf8
63             mysql_collate: utf8_general_ci
64           order: 3
65 EOSCHEMA
66
67 my $mysql_out = <<EOSQL;
68 SET foreign_key_checks=0;
69
70 CREATE TABLE thing (
71   name varchar(32),
72   swedish_name varchar(32) CHARACTER SET swe7,
73   description text CHARACTER SET utf8 COLLATE utf8_general_ci
74 ) Type=InnoDB DEFAULT CHARACTER SET latin1 COLLATE latin1_danish_ci;
75
76 EOSQL
77
78     my $sqlt;
79     $sqlt = SQL::Translator->new(
80         show_warnings  => 1,
81         no_comments    => 1,
82         from           => "YAML",
83         to             => "MySQL",
84     );
85
86     my $out = $sqlt->translate(\$yaml_in)
87     or die "Translate error:".$sqlt->error;
88     ok $out ne ""                 ,"Produced something!";
89     eq_or_diff $out, $mysql_out   ,"Output looks right";
90 }