File: 49xml-to-pg-samefield.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 (54 lines) | stat: -rw-r--r-- 1,229 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/perl
use strict;

use FindBin qw/$Bin/;
use Test::More;
use Test::SQL::Translator;
use Test::Exception;
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/samefield.xml";

my $sqlt;
$sqlt = SQL::Translator->new(
    no_comments => 1,
    show_warnings  => 1,
    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;

is($sql, << "SQL");
DROP TABLE "one" CASCADE;
CREATE TABLE "one" (
  "same" character varying(100) DEFAULT 'hello' NOT NULL
);

DROP TABLE "two" CASCADE;
CREATE TABLE "two" (
  "same" character varying(100) DEFAULT 'hello' NOT NULL
);

SQL

### This doesnt work, cant add a field with a name thats already there, so how do we test dupe field names?!

# my $table = $sqlt->schema->get_table('two');
# $table->add_field(name => 'same');
# print Dumper($table);
# $sql = SQL::Translator::Producer::PostgreSQL::produce($sqlt);
# print ">>$sql<<\n";