* Add support for CHECK constraint in SQLite producer (GH#57)
* Fix forgotten quoting in the MySQL DROP TABLE diff producer (GH#50)
* Fix Pg grammar parsing of UUID, time, timetz columns (RT#100196, GH#52)
+ * Add support for USING and WHERE on indexes in PostgreSQL producer
+ (RT#63814, GH#52)
* Improve add_trigger consistency between producers (GH#48)
* Declare dependencies in deterministic order (RT#102859)
* Multiple speedups of naive internal debugging mechanism (GH#54)
my @fields = $index->fields;
return unless @fields;
+ my $index_using;
+ my $index_where;
+ for my $opt ( $index->options ) {
+ if ( ref $opt eq 'HASH' ) {
+ foreach my $key (keys %$opt) {
+ my $value = $opt->{$key};
+ next unless defined $value;
+ if ( uc($key) eq 'USING' ) {
+ $index_using = "USING $value";
+ }
+ elsif ( uc($key) eq 'WHERE' ) {
+ $index_where = "WHERE $value";
+ }
+ }
+ }
+ }
+
my $def_start = 'CONSTRAINT ' . $generator->quote($name) . ' ';
my $field_names = '(' . join(", ", (map { $_ =~ /\(.*\)/ ? $_ : ( $generator->quote($_) ) } @fields)) . ')';
if ( $type eq PRIMARY_KEY ) {
}
elsif ( $type eq NORMAL ) {
$index_def =
- 'CREATE INDEX ' . $generator->quote($name) . ' on ' . $generator->quote($table_name) . ' ' . $field_names
- ;
+ 'CREATE INDEX ' . $generator->quote($name) . ' on ' . $generator->quote($table_name) . ' ' .
+ join ' ', grep { defined } $index_using, $field_names, $index_where;
}
else {
warn "Unknown index type ($type) on table $table_name.\n"
($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 };