Pg views and sqlite views, patch from wreis
[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"),
49 Constraint "emailuniqueindex" UNIQUE ("email")
50);
51CREATE INDEX "titleindex" on "Basic" ("title");
b08b5416 52
53
cc00c034 54DROP TABLE "Another" CASCADE;
b08b5416 55CREATE TABLE "Another" (
56 "id" serial NOT NULL,
57 PRIMARY KEY ("id")
58);
59
296c2701 60
61
a25ac5d2 62DROP VIEW "email_list";
63CREATE VIEW "email_list" ( "email" ) AS (
296c2701 64 SELECT email FROM Basic WHERE email IS NOT NULL
65 );
66
b08b5416 67ALTER TABLE "Basic" ADD FOREIGN KEY ("another_id")
5342f5c1 68 REFERENCES "Another" ("id") DEFERRABLE;
8c4efd11 69SQL