Changes for SQL::Translator
* Add support for parsing PostgreSQL dollar-quoted strings
+ * Add support for materialized views in Oracle producer
* switched JSON backend from JSON.pm to JSON::MaybeXS
0.11024 2018-01-09
my ($view, $options) = @_;
my $qt = $options->{quote_table_names};
my $view_name = quote($view->name,$qt);
+ my $extra = $view->extra;
+
+ my $view_type = 'VIEW';
+ my $view_options = '';
+ if ( my $materialized = $extra->{materialized} ) {
+ $view_type = 'MATERIALIZED VIEW';
+ $view_options .= ' '.$materialized;
+ }
my @create;
- push @create, qq[DROP VIEW $view_name]
+ push @create, qq[DROP $view_type $view_name]
if $options->{add_drop_view};
- push @create, sprintf("CREATE VIEW %s AS\n%s",
+ push @create, sprintf("CREATE %s %s%s AS\n%s",
+ $view_type,
$view_name,
+ $view_options,
$view->sql);
return \@create;
use SQL::Translator::Schema::Constants;
use SQL::Translator::Schema::Table;
+use SQL::Translator::Schema::View;
use SQL::Translator::Schema::Field;
use SQL::Translator::Schema::Constraint;
use SQL::Translator::Producer::Oracle;
],
'correct "CREATE CONSTRAINT" SQL'
);
+
+ my $materialized_view = SQL::Translator::Schema::View->new(
+ name => 'matview',
+ sql => 'SELECT id, name FROM table3',
+ fields => 'id, name',
+ extra => {
+ materialized =>
+ 'REFRESH START WITH SYSDATE NEXT SYSDATE + 5/1440 FORCE WITH ROWID'
+ }
+ );
+
+ my ($materialized_view_def) = SQL::Translator::Producer::Oracle::create_view($materialized_view);
+ is_deeply(
+ $materialized_view_def,
+ [ "CREATE MATERIALIZED VIEW matview REFRESH START WITH SYSDATE NEXT SYSDATE + 5/1440 FORCE WITH ROWID AS\nSELECT id, name FROM table3"
+ ],
+ 'correct "CREATE MATERIALZED VIEW" SQL'
+ );
+
}
done_testing();