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(224, '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",
94 name => "description",
101 data_type => "varchar",
104 default_value => undef,
113 name => "explicitnulldef",
114 data_type => "varchar",
115 default_value => undef,
120 name => "explicitemptystring",
121 data_type => "varchar",
127 name => "emptytagdef",
128 data_type => "varchar",
131 comments => "Hello emptytagdef",
135 name => "another_id",
144 data_type => "timestamp",
160 name => 'emailuniqueindex',
166 fields => ["another_id"],
167 reference_table => "Another",
168 reference_fields => ["id"],
174 name => "titleindex",
191 options => [ { ENGINE => 'InnoDB' } ],
196 default_value => undef,
200 is_auto_increment => 1,
204 data_type => "numeric",
205 default_value => undef,
209 }, # end table Another
214 name => 'email_list',
215 sql => "SELECT email FROM Basic WHERE (email IS NOT NULL)",
227 name => 'foo_trigger',
228 perform_action_when => 'after',
229 database_events => 'insert',
231 action => 'update modified=timestamp();',
239 name => 'bar_trigger',
240 perform_action_when => 'before',
241 database_events => 'insert,update',
243 action => 'update modified2=timestamp();',
253 sql => 'select foo from bar',
254 parameters => ['foo', 'bar'],
256 comments => 'Go Sox!',