Improve trigger 'scope' attribute support (RT#119997)
[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,
9768b204 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 => '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 '',
21d62b63 42 "email" character varying(500),
8c4efd11 43 "explicitnulldef" character varying,
44 "explicitemptystring" character varying DEFAULT '',
45 -- Hello emptytagdef
46 "emptytagdef" character varying DEFAULT '',
06baeb21 47 "another_id" integer DEFAULT 2,
ad258776 48 "timest" timestamp,
8c4efd11 49 PRIMARY KEY ("id"),
3b9249fb 50 CONSTRAINT "emailuniqueindex" UNIQUE ("email"),
51 CONSTRAINT "very_long_index_name_on_title_field_which_should_be_truncated_for_various_rdbms" UNIQUE ("title")
8c4efd11 52);
53CREATE INDEX "titleindex" on "Basic" ("title");
b08b5416 54
cc00c034 55DROP TABLE "Another" CASCADE;
b08b5416 56CREATE TABLE "Another" (
57 "id" serial NOT NULL,
c3bddac9 58 "num" numeric(10,2),
b08b5416 59 PRIMARY KEY ("id")
60);
61
a25ac5d2 62DROP VIEW "email_list";
f59b2c0e 63CREATE VIEW "email_list" ( "email" ) AS
3910f248 64 SELECT email FROM Basic WHERE (email IS NOT NULL)
f59b2c0e 65;
296c2701 66
c9c8f3e1 67DROP TRIGGER IF EXISTS "foo_trigger";
c96cd4a8 68
c0ec0e22 69CREATE TRIGGER "foo_trigger" after insert ON "Basic" FOR EACH row update modified=timestamp();;
c96cd4a8 70
c9c8f3e1 71DROP TRIGGER IF EXISTS "bar_trigger";
c96cd4a8 72
c0ec0e22 73CREATE TRIGGER "bar_trigger" before insert OR update ON "Basic" FOR EACH row update modified2=timestamp();;
c96cd4a8 74
b08b5416 75ALTER TABLE "Basic" ADD FOREIGN KEY ("another_id")
5342f5c1 76 REFERENCES "Another" ("id") DEFERRABLE;
2ae88fa4 77
8c4efd11 78SQL