File: 46xml-to-pg.t

package info (click to toggle)
libsql-translator-perl 0.11011-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 15,380 kB
  • sloc: perl: 251,748; sql: 3,805; xml: 233; makefile: 7
file content (78 lines) | stat: -rw-r--r-- 1,979 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/perl
use strict;

use FindBin qw/$Bin/;
use Test::More;
use Test::SQL::Translator;
use Test::Exception;
use Test::Differences;
use Data::Dumper;
use SQL::Translator;
use SQL::Translator::Schema::Constants;


BEGIN {
    maybe_plan(1, 'SQL::Translator::Parser::XML::SQLFairy',
              'SQL::Translator::Producer::PostgreSQL');
}

my $xmlfile = "$Bin/data/xml/schema.xml";

my $sqlt;
$sqlt = SQL::Translator->new(
    no_comments => 1,
    show_warnings  => 0,
    add_drop_table => 1,
);

die "Can't find test schema $xmlfile" unless -e $xmlfile;

my $sql = $sqlt->translate(
    from     => 'XML-SQLFairy',
    to       => 'PostgreSQL',
    filename => $xmlfile,
) or die $sqlt->error;

eq_or_diff($sql, << "SQL");
DROP TABLE "Basic" CASCADE;
CREATE TABLE "Basic" (
  "id" serial NOT NULL,
  "title" character varying(100) DEFAULT 'hello' NOT NULL,
  "description" text DEFAULT '',
  "email" character varying(500),
  "explicitnulldef" character varying,
  "explicitemptystring" character varying DEFAULT '',
  -- Hello emptytagdef
  "emptytagdef" character varying DEFAULT '',
  "another_id" integer DEFAULT 2,
  "timest" timestamp,
  PRIMARY KEY ("id"),
  CONSTRAINT "emailuniqueindex" UNIQUE ("email"),
  CONSTRAINT "very_long_index_name_on_title_field_which_should_be_truncated_for_various_rdbms" UNIQUE ("title")
);
CREATE INDEX "titleindex" on "Basic" ("title");

DROP TABLE "Another" CASCADE;
CREATE TABLE "Another" (
  "id" serial NOT NULL,
  "num" numeric(10,2),
  PRIMARY KEY ("id")
);

DROP VIEW "email_list";
CREATE VIEW "email_list" ( "email" ) AS
    SELECT email FROM Basic WHERE (email IS NOT NULL)
;

DROP TRIGGER IF EXISTS foo_trigger;

CREATE TRIGGER foo_trigger after insert ON Basic update modified=timestamp();;

DROP TRIGGER IF EXISTS bar_trigger;

CREATE TRIGGER bar_trigger before insert OR update ON Basic update modified2=timestamp();;

ALTER TABLE "Basic" ADD FOREIGN KEY ("another_id")
  REFERENCES "Another" ("id") DEFERRABLE;

SQL