Improve xml database_event deprecation warning
[dbsrgits/SQL-Translator.git] / t / 48xml-to-sqlite.t
CommitLineData
8c4efd11 1#!/usr/bin/perl
2use strict;
3
4use FindBin qw/$Bin/;
5use Test::More;
6use Test::SQL::Translator;
7use Test::Exception;
4d438549 8use Test::Differences;
8c4efd11 9use Data::Dumper;
10use SQL::Translator;
11use SQL::Translator::Schema::Constants;
12
13
14BEGIN {
24d9fe69 15 maybe_plan(2, 'SQL::Translator::Parser::XML::SQLFairy',
8c4efd11 16 'SQL::Translator::Producer::SQLite');
17}
18
19my $xmlfile = "$Bin/data/xml/schema.xml";
20
21my $sqlt;
22$sqlt = SQL::Translator->new(
23 no_comments => 1,
ee91ab6f 24 show_warnings => 0,
8c4efd11 25 add_drop_table => 1,
26);
27
28die "Can't find test schema $xmlfile" unless -e $xmlfile;
29
30my $sql = $sqlt->translate(
31 from => 'XML-SQLFairy',
32 to => 'SQLite',
33 filename => $xmlfile,
34) or die $sqlt->error;
35
4d438549 36eq_or_diff($sql, << "SQL");
f9c96971 37
38
8c4efd11 39BEGIN TRANSACTION;
40
8c4efd11 41DROP TABLE Basic;
24d9fe69 42
8c4efd11 43CREATE TABLE Basic (
44 id INTEGER PRIMARY KEY NOT NULL,
45 title varchar(100) NOT NULL DEFAULT 'hello',
46 description text DEFAULT '',
47 email varchar(255),
48 explicitnulldef varchar,
49 explicitemptystring varchar DEFAULT '',
50 -- Hello emptytagdef
08d91aad 51 emptytagdef varchar DEFAULT '',
b08b5416 52 another_id int(10) DEFAULT '2',
08d91aad 53 timest timestamp
8c4efd11 54);
55
4d438549 56CREATE INDEX titleindex_Basic ON Basic (title);
24d9fe69 57
4d438549 58CREATE UNIQUE INDEX emailuniqueindex_Basic ON Basic (email);
8c4efd11 59
b08b5416 60DROP TABLE Another;
24d9fe69 61
b08b5416 62CREATE TABLE Another (
63 id INTEGER PRIMARY KEY NOT NULL
64);
65
a25ac5d2 66DROP VIEW IF EXISTS email_list;
67CREATE VIEW email_list AS
68 SELECT email FROM Basic WHERE email IS NOT NULL;
ec59a597 69
f9c96971 70DROP TRIGGER IF EXISTS foo_trigger;
71
72CREATE TRIGGER foo_trigger after insert on Basic BEGIN update modified=timestamp(); END;
73
8c4efd11 74COMMIT;
75SQL
24d9fe69 76
77# Test in list context
78my @sql = $sqlt->translate(
79 from => 'XML-SQLFairy',
80 to => 'SQLite',
81 filename => $xmlfile,
82) or die $sqlt->error;
83
f9c96971 84eq_or_diff(\@sql,
24d9fe69 85 [
f9c96971 86 "\n\nBEGIN TRANSACTION",
24d9fe69 87 'DROP TABLE Basic',
88 'CREATE TABLE Basic (
89 id INTEGER PRIMARY KEY NOT NULL,
90 title varchar(100) NOT NULL DEFAULT \'hello\',
91 description text DEFAULT \'\',
92 email varchar(255),
93 explicitnulldef varchar,
94 explicitemptystring varchar DEFAULT \'\',
95 -- Hello emptytagdef
96 emptytagdef varchar DEFAULT \'\',
97 another_id int(10) DEFAULT \'2\',
98 timest timestamp
99)',
100 'CREATE INDEX titleindex_Basic02 ON Basic (title)',
101 'CREATE UNIQUE INDEX emailuniqueindex_Basic02 ON Basic (email)',
102 'DROP TABLE Another',
103 'CREATE TABLE Another (
104 id INTEGER PRIMARY KEY NOT NULL
105)',
106 'DROP VIEW IF EXISTS email_list;
107CREATE VIEW email_list AS
108 SELECT email FROM Basic WHERE email IS NOT NULL',
f9c96971 109 'DROP TRIGGER IF EXISTS foo_trigger',
110 'CREATE TRIGGER foo_trigger after insert on Basic BEGIN update modified=timestamp(); END',
24d9fe69 111 'COMMIT'
112 ], 'SQLite translate in list context matches');
113
114