From: Alexander Hartmaier Date: Thu, 7 Apr 2016 14:50:23 +0000 (+0200) Subject: Add support for materialized views in Oracle producer X-Git-Tag: v1.59_01~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8d59dd515dae2a6d6dd50da7aa7eb2367042e8e8;p=dbsrgits%2FSQL-Translator.git Add support for materialized views in Oracle producer --- diff --git a/Changes b/Changes index e70308f..b022e5b 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ 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 diff --git a/lib/SQL/Translator/Producer/Oracle.pm b/lib/SQL/Translator/Producer/Oracle.pm index d3f7a12..929fc8e 100644 --- a/lib/SQL/Translator/Producer/Oracle.pm +++ b/lib/SQL/Translator/Producer/Oracle.pm @@ -732,13 +732,23 @@ sub create_view { 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; diff --git a/t/55-oracle-producer.t b/t/55-oracle-producer.t index 8f90c31..57e25ea 100644 --- a/t/55-oracle-producer.t +++ b/t/55-oracle-producer.t @@ -7,6 +7,7 @@ use Test::More; 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; @@ -78,6 +79,25 @@ 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();