PgSQL diff patch from wries
[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;
8use Data::Dumper;
9use SQL::Translator;
10use SQL::Translator::Schema::Constants;
11
12
13BEGIN {
14 maybe_plan(1, 'SQL::Translator::Parser::XML::SQLFairy',
15 'SQL::Translator::Producer::PostgreSQL');
16}
17
18my $xmlfile = "$Bin/data/xml/schema.xml";
19
20my $sqlt;
21$sqlt = SQL::Translator->new(
22 no_comments => 1,
23 show_warnings => 1,
24 add_drop_table => 1,
25);
26
27die "Can't find test schema $xmlfile" unless -e $xmlfile;
28
29my $sql = $sqlt->translate(
30 from => 'XML-SQLFairy',
31 to => 'PostgreSQL',
32 filename => $xmlfile,
33) or die $sqlt->error;
34
35is($sql, << "SQL");
cc00c034 36DROP TABLE "Basic" CASCADE;
8c4efd11 37CREATE TABLE "Basic" (
38 "id" serial NOT NULL,
39 "title" character varying(100) DEFAULT 'hello' NOT NULL,
40 "description" text DEFAULT '',
41 "email" character varying(255),
42 "explicitnulldef" character varying,
43 "explicitemptystring" character varying DEFAULT '',
44 -- Hello emptytagdef
45 "emptytagdef" character varying DEFAULT '',
b08b5416 46 "another_id" integer DEFAULT '2',
08d91aad 47 "timest" timestamp(0),
8c4efd11 48 PRIMARY KEY ("id"),
3406fd5b 49 CONSTRAINT "emailuniqueindex" UNIQUE ("email")
8c4efd11 50);
51CREATE INDEX "titleindex" on "Basic" ("title");
b08b5416 52
cc00c034 53DROP TABLE "Another" CASCADE;
b08b5416 54CREATE TABLE "Another" (
55 "id" serial NOT NULL,
56 PRIMARY KEY ("id")
57);
58
a25ac5d2 59DROP VIEW "email_list";
60CREATE VIEW "email_list" ( "email" ) AS (
296c2701 61 SELECT email FROM Basic WHERE email IS NOT NULL
62 );
63
b08b5416 64ALTER TABLE "Basic" ADD FOREIGN KEY ("another_id")
5342f5c1 65 REFERENCES "Another" ("id") DEFERRABLE;
8c4efd11 66SQL