Commit | Line | Data |
8c4efd11 |
1 | #!/usr/bin/perl |
2 | use strict; |
3 | |
4 | use FindBin qw/$Bin/; |
5 | use Test::More; |
6 | use Test::SQL::Translator; |
7 | use Test::Exception; |
2ae88fa4 |
8 | use Test::Differences; |
8c4efd11 |
9 | use Data::Dumper; |
10 | use SQL::Translator; |
11 | use SQL::Translator::Schema::Constants; |
12 | |
13 | |
14 | BEGIN { |
15 | maybe_plan(1, 'SQL::Translator::Parser::XML::SQLFairy', |
16 | 'SQL::Translator::Producer::PostgreSQL'); |
17 | } |
18 | |
19 | my $xmlfile = "$Bin/data/xml/schema.xml"; |
20 | |
21 | my $sqlt; |
22 | $sqlt = SQL::Translator->new( |
23 | no_comments => 1, |
9768b204 |
24 | show_warnings => 0, |
8c4efd11 |
25 | add_drop_table => 1, |
26 | ); |
27 | |
28 | die "Can't find test schema $xmlfile" unless -e $xmlfile; |
29 | |
30 | my $sql = $sqlt->translate( |
31 | from => 'XML-SQLFairy', |
32 | to => 'PostgreSQL', |
33 | filename => $xmlfile, |
34 | ) or die $sqlt->error; |
35 | |
2ae88fa4 |
36 | eq_or_diff($sql, << "SQL"); |
cc00c034 |
37 | DROP TABLE "Basic" CASCADE; |
8c4efd11 |
38 | CREATE 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 '', |
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 | ); |
52 | CREATE INDEX "titleindex" on "Basic" ("title"); |
b08b5416 |
53 | |
cc00c034 |
54 | DROP TABLE "Another" CASCADE; |
b08b5416 |
55 | CREATE TABLE "Another" ( |
56 | "id" serial NOT NULL, |
57 | PRIMARY KEY ("id") |
58 | ); |
59 | |
a25ac5d2 |
60 | DROP VIEW "email_list"; |
f59b2c0e |
61 | CREATE VIEW "email_list" ( "email" ) AS |
3910f248 |
62 | SELECT email FROM Basic WHERE (email IS NOT NULL) |
f59b2c0e |
63 | ; |
296c2701 |
64 | |
b08b5416 |
65 | ALTER TABLE "Basic" ADD FOREIGN KEY ("another_id") |
5342f5c1 |
66 | REFERENCES "Another" ("id") DEFERRABLE; |
2ae88fa4 |
67 | |
8c4efd11 |
68 | SQL |