6 use Test::SQL::Translator;
11 use SQL::Translator::Schema::Constants;
15 maybe_plan(2, 'SQL::Translator::Parser::XML::SQLFairy',
16 'SQL::Translator::Producer::MySQL');
19 my $xmlfile = "$Bin/data/xml/schema.xml";
22 $sqlt = SQL::Translator->new(
27 mysql_version => 5.005,
31 die "Can't find test schema $xmlfile" unless -e $xmlfile;
34 q[SET foreign_key_checks=0],
36 q[DROP TABLE IF EXISTS `Basic`],
37 q[CREATE TABLE `Basic` (
38 `id` integer(10) zerofill auto_increment,
39 `title` varchar(100) NOT NULL DEFAULT 'hello',
40 `description` text DEFAULT '',
42 `explicitnulldef` varchar(255),
43 `explicitemptystring` varchar(255) DEFAULT '',
44 `emptytagdef` varchar(255) DEFAULT '' comment 'Hello emptytagdef',
45 `another_id` integer(10) DEFAULT 2,
47 INDEX `titleindex` (`title`),
50 UNIQUE `emailuniqueindex` (`email`),
51 UNIQUE `very_long_index_name_on_title_field_which_should_be_tru_14b59999` (`title`),
52 CONSTRAINT `Basic_fk` FOREIGN KEY (`another_id`) REFERENCES `Another` (`id`)
55 q[DROP TABLE IF EXISTS `Another`],
56 q[CREATE TABLE `Another` (
57 `id` integer(10) auto_increment,
62 VIEW `email_list` ( `email` ) AS
63 SELECT email FROM Basic WHERE (email IS NOT NULL)
66 q[DROP TRIGGER IF EXISTS `foo_trigger`],
67 q[CREATE TRIGGER `foo_trigger` after insert ON `Basic`
68 FOR EACH ROW BEGIN update modified=timestamp(); END],
70 q[DROP TRIGGER IF EXISTS `bar_trigger_insert`],
71 q[CREATE TRIGGER `bar_trigger_insert` before insert ON `Basic`
72 FOR EACH ROW BEGIN update modified2=timestamp(); END],
74 q[DROP TRIGGER IF EXISTS `bar_trigger_update`],
75 q[CREATE TRIGGER `bar_trigger_update` before update ON `Basic`
76 FOR EACH ROW BEGIN update modified2=timestamp(); END],
78 q[SET foreign_key_checks=1],
81 my $sql = $sqlt->translate(
82 from => 'XML-SQLFairy',
85 ) or die $sqlt->error;
87 eq_or_diff($sql, join("", map { "$_;\n\n" } @want));
89 my @sql = $sqlt->translate(
90 from => 'XML-SQLFairy',
93 ) or die $sqlt->error;
95 is_deeply(\@sql, \@want);