#=============================================================================
BEGIN {
- maybe_plan(7,
+ maybe_plan(9,
'SQL::Translator::Producer::PostgreSQL',
'Test::Differences',
)
is($field5_sql, 'enum_field mytable_enum_field_type NOT NULL', 'Create real enum field works');
+my $view1 = SQL::Translator::Schema::View->new(
+ name => 'view_foo',
+ fields => [qw/id name/],
+ sql => 'SELECT id, name FROM thing',
+);
+my $create_opts = { add_replace_view => 1, no_comments => 1 };
+my $view1_sql1 = SQL::Translator::Producer::PostgreSQL::create_view($view1, $create_opts);
+
+my $view_sql_replace = "CREATE OR REPLACE VIEW view_foo ( id, name ) AS (
+ SELECT id, name FROM thing
+ );\n\n";
+is($view1_sql1, $view_sql_replace, 'correct "CREATE OR REPLACE VIEW" SQL');
+
+my $view2 = SQL::Translator::Schema::View->new(
+ name => 'view_foo2',
+ sql => 'SELECT id, name FROM thing',
+ extra => {
+ 'temporary' => '1',
+ 'check_option' => 'cascaded',
+ },
+);
+my $create2_opts = { add_replace_view => 1, no_comments => 1 };
+my $view2_sql1 = SQL::Translator::Producer::PostgreSQL::create_view($view2, $create2_opts);
+
+my $view2_sql_replace = "CREATE OR REPLACE TEMPORARY VIEW view_foo2 AS (
+ SELECT id, name FROM thing
+ ) WITH CASCADED CHECK OPTION;\n\n";
+is($view2_sql1, $view2_sql_replace, 'correct "CREATE OR REPLACE VIEW" SQL 2');