$index->fields;
next unless @fields;
+ my @index_options;
+ for my $opt ( $index->options ) {
+ if ( ref $opt eq 'HASH' ) {
+ my ( $key, $value ) = each %$opt;
+ if ( ref $value eq 'ARRAY' ) {
+ push @table_options, "$key\n(\n". join ("\n",
+ map { " $_->[0]\t$_->[1]" }
+ map { [ each %$_ ] }
+ @$value
+ )."\n)";
+ }
+ elsif ( !defined $value ) {
+ push @index_options, $key;
+ }
+ else {
+ push @index_options, "$key $value";
+ }
+ }
+ }
+ my $index_options = @index_options
+ ? "\n".join("\n", @index_options) : '';
+
if ( $index_type eq PRIMARY_KEY ) {
$index_name = $index_name ? mk_name( $index_name )
: mk_name( $table_name, 'pk' );
push @index_defs,
"CREATE INDEX $index_name on $table_name_ur (".
join( ', ', @fields ).
- ");";
+ ")$index_options;";
}
elsif ( $index_type eq UNIQUE ) {
$index_name = $index_name ? mk_name( $index_name )
push @index_defs,
"CREATE UNIQUE INDEX $index_name on $table_name_ur (".
join( ', ', @fields ).
- ");";
+ ")$index_options;";
}
else {
warn "Unknown index type ($index_type) on table $table_name.\n"
--- /dev/null
+#!/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(3, 'SQL::Translator::Parser::YAML',
+ 'SQL::Translator::Producer::Oracle');
+}
+
+my $yamlfile = "$Bin/data/oracle/schema_with_options.yaml";
+
+my $sqlt;
+$sqlt = SQL::Translator->new(
+ show_warnings => 0,
+ add_drop_table => 0,
+);
+
+my $sql_string = $sqlt->translate(
+ from => 'YAML',
+ to => 'Oracle',
+ filename => $yamlfile,
+);
+
+warn $sql_string;
+ok($sql_string, 'Translation successfull');
+ok($sql_string =~ /TABLESPACE\s+DATA/, 'Table options');
+ok($sql_string =~ /TABLESPACE\s+INDX/, 'Index options');