#=============================================================================
BEGIN {
- maybe_plan(57,
+ maybe_plan(undef,
'SQL::Translator::Producer::PostgreSQL',
'Test::Differences',
)
my $field5 = SQL::Translator::Schema::Field->new( name => 'enum_field',
table => $table,
data_type => 'enum',
- extra => { list => [ 'Foo', 'Bar' ] },
+ extra => { list => [ 'Foo', 'Bar', 'Ba\'z' ] },
is_auto_increment => 0,
is_nullable => 0,
is_foreign_key => 0,
is_unique => 0 );
-my $field5_sql = SQL::Translator::Producer::PostgreSQL::create_field($field5,{ postgres_version => 8.3 });
+my $field5_types = {};
+my $field5_sql = SQL::Translator::Producer::PostgreSQL::create_field(
+ $field5,
+ {
+ postgres_version => 8.3,
+ type_defs => $field5_types,
+ }
+);
is($field5_sql, 'enum_field mytable_enum_field_type NOT NULL', 'Create real enum field works');
-
-
-
+is_deeply(
+ $field5_types,
+ { mytable_enum_field_type =>
+ "DROP TYPE IF EXISTS mytable_enum_field_type CASCADE;\n" .
+ "CREATE TYPE mytable_enum_field_type AS ENUM ('Foo', 'Bar', 'Ba''z')"
+ },
+ 'Create real enum type works'
+);
my $field6 = SQL::Translator::Schema::Field->new(
name => 'character',
my $field13 = SQL::Translator::Schema::Field->new( name => 'enum_field_with_type_name',
table => $table,
data_type => 'enum',
- extra => { list => [ 'Foo', 'Bar' ],
+ extra => { list => [ 'Foo', 'Bar', 'Ba\'z' ],
custom_type_name => 'real_enum_type' },
is_auto_increment => 0,
is_nullable => 0,
is_foreign_key => 0,
is_unique => 0 );
-my $field13_sql = SQL::Translator::Producer::PostgreSQL::create_field($field13,{ postgres_version => 8.3 });
+my $field13_types = {};
+my $field13_sql = SQL::Translator::Producer::PostgreSQL::create_field(
+ $field13,
+ {
+ postgres_version => 8.3,
+ type_defs => $field13_types,
+ }
+);
is($field13_sql, 'enum_field_with_type_name real_enum_type NOT NULL', 'Create real enum field works');
+is_deeply(
+ $field13_types,
+ { real_enum_type =>
+ "DROP TYPE IF EXISTS real_enum_type CASCADE;\n" .
+ "CREATE TYPE real_enum_type AS ENUM ('Foo', 'Bar', 'Ba''z')"
+ },
+ 'Create real enum type works'
+);
{
($def) = SQL::Translator::Producer::PostgreSQL::create_constraint($constr, $quote);
is($def->[0], 'CONSTRAINT "constr" UNIQUE ("bar", lower(foo))', 'constraint created w/ quotes');
}
+
+ {
+ my $index = $table->add_index(name => 'myindex', options => [{using => 'hash'}, {where => "upper(foo) = 'bar' AND bar = 'foo'"}], fields => ['bar', 'lower(foo)']);
+ my ($def) = SQL::Translator::Producer::PostgreSQL::create_index($index);
+ is($def, "CREATE INDEX myindex on foobar USING hash (bar, lower(foo)) WHERE upper(foo) = 'bar' AND bar = 'foo'", 'index using & where created');
+ ($def) = SQL::Translator::Producer::PostgreSQL::create_index($index, $quote);
+ is($def, 'CREATE INDEX "myindex" on "foobar" USING hash ("bar", lower(foo)) WHERE upper(foo) = \'bar\' AND bar = \'foo\'', 'index using & where created w/ quotes');
+ }
}
my $drop_view_opts1 = { add_drop_view => 1, no_comments => 1, postgres_version => 8.001 };
";
is($drop_view_9_1_produced, $drop_view_9_1_expected, "My DROP VIEW statement for 9.1 is correct");
+
+done_testing;