Todoify test - probably not in this lifetime
[dbsrgits/SQL-Translator.git] / t / 46xml-to-pg.t
CommitLineData
8c4efd11 1#!/usr/bin/perl
2use strict;
3
4use FindBin qw/$Bin/;
5use Test::More;
6use Test::SQL::Translator;
7use Test::Exception;
2ae88fa4 8use Test::Differences;
8c4efd11 9use Data::Dumper;
10use SQL::Translator;
11use SQL::Translator::Schema::Constants;
12
13
14BEGIN {
15 maybe_plan(1, 'SQL::Translator::Parser::XML::SQLFairy',
16 'SQL::Translator::Producer::PostgreSQL');
17}
18
19my $xmlfile = "$Bin/data/xml/schema.xml";
20
21my $sqlt;
22$sqlt = SQL::Translator->new(
23 no_comments => 1,
24 show_warnings => 1,
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 => 'PostgreSQL',
33 filename => $xmlfile,
34) or die $sqlt->error;
35
2ae88fa4 36eq_or_diff($sql, << "SQL");
cc00c034 37DROP TABLE "Basic" CASCADE;
8c4efd11 38CREATE TABLE "Basic" (
39 "id" serial NOT NULL,
40 "title" character varying(100) DEFAULT 'hello' NOT NULL,
41 "description" text DEFAULT '',
42 "email" character varying(255),
43 "explicitnulldef" character varying,
44 "explicitemptystring" character varying DEFAULT '',
45 -- Hello emptytagdef
46 "emptytagdef" character varying DEFAULT '',
b08b5416 47 "another_id" integer DEFAULT '2',
08d91aad 48 "timest" timestamp(0),
8c4efd11 49 PRIMARY KEY ("id"),
3406fd5b 50 CONSTRAINT "emailuniqueindex" UNIQUE ("email")
8c4efd11 51);
52CREATE INDEX "titleindex" on "Basic" ("title");
b08b5416 53
cc00c034 54DROP TABLE "Another" CASCADE;
b08b5416 55CREATE TABLE "Another" (
56 "id" serial NOT NULL,
57 PRIMARY KEY ("id")
58);
59
a25ac5d2 60DROP VIEW "email_list";
61CREATE VIEW "email_list" ( "email" ) AS (
296c2701 62 SELECT email FROM Basic WHERE email IS NOT NULL
63 );
64
b08b5416 65ALTER TABLE "Basic" ADD FOREIGN KEY ("another_id")
5342f5c1 66 REFERENCES "Another" ("id") DEFERRABLE;
2ae88fa4 67
8c4efd11 68SQL