4 # Before `make install' is performed this script should be runnable with
5 # `make test'. After `make install' it should work as `perl test.pl'
7 # Run script with -d for debug.
14 use Test::SQL::Translator;
18 use SQL::Translator::Schema::Constants;
20 # Simple options. -d for debug
22 BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; }
23 use constant DEBUG => (exists $opt{d} ? 1 : 0);
27 #=============================================================================
30 maybe_plan(238, 'SQL::Translator::Parser::XML::SQLFairy');
33 my $testschema = "$Bin/data/xml/schema.xml";
36 $sqlt = SQL::Translator->new(
41 die "Can't find test schema $testschema" unless -e $testschema;
46 local $SIG{__WARN__} = sub { push @w, $_[0] if $_[0] =~ /The database_event tag is deprecated - please use database_events/ };
48 $sql = $sqlt->translate(
49 from => 'XML-SQLFairy',
51 filename => $testschema,
52 ) or die $sqlt->error;
55 ok (@w, 'database_event deprecation warning issued');
58 # Test the schema objs generted from the XML
60 my $scma = $sqlt->schema;
62 # Hmmm, when using schema_ok the field test data gets a bit too nested and
63 # fiddly to work with. (See 28xml-xmi-parser-sqlfairy.t for more a split out
69 options => [ { ENGINE => 'InnoDB' } ],
79 default_value => undef,
83 is_auto_increment => 1,
84 extra => { ZEROFILL => 1 },
88 data_type => "varchar",
90 default_value => "hello",
95 name => "description",
102 data_type => "varchar",
105 default_value => undef,
114 name => "explicitnulldef",
115 data_type => "varchar",
116 default_value => undef,
121 name => "explicitemptystring",
122 data_type => "varchar",
128 name => "emptytagdef",
129 data_type => "varchar",
132 comments => "Hello emptytagdef",
136 name => "another_id",
145 data_type => "timestamp",
161 name => 'emailuniqueindex',
166 name => 'very_long_index_name_on_title_field_which_should_be_truncated_for_various_rdbms',
172 fields => ["another_id"],
173 reference_table => "Another",
174 reference_fields => ["id"],
180 name => "titleindex",
197 options => [ { ENGINE => 'InnoDB' } ],
202 default_value => undef,
206 is_auto_increment => 1,
210 data_type => "numeric",
211 default_value => undef,
215 }, # end table Another
220 name => 'email_list',
221 sql => "SELECT email FROM Basic WHERE (email IS NOT NULL)",
233 name => 'foo_trigger',
234 perform_action_when => 'after',
235 database_events => 'insert',
237 action => 'update modified=timestamp();',
245 name => 'bar_trigger',
246 perform_action_when => 'before',
247 database_events => 'insert,update',
249 action => 'update modified2=timestamp();',
259 sql => 'select foo from bar',
260 parameters => ['foo', 'bar'],
262 comments => 'Go Sox!',