Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CREATE UNLOGGED TABLE support for PostgreSQL #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/SQL/Translator/Producer/PostgreSQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ my %truncated;

=head1 PostgreSQL Create Table Syntax

CREATE [ [ LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name (
CREATE [ [ LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE table_name (
{ column_name data_type [ DEFAULT default_expr ] [ column_constraint [, ... ] ]
| table_constraint } [, ... ]
)
Expand Down Expand Up @@ -321,8 +321,11 @@ sub create_table
$create_statement .= "DROP TABLE $table_name_qt CASCADE;\n";
}
}
my $temporary = $table->extra->{temporary} ? "TEMPORARY " : "";
$create_statement .= "CREATE ${temporary}TABLE $table_name_qt (\n" .
my $parameter =
$table->extra->{temporary} ? "TEMPORARY "
: $table->extra->{unlogged} ? "UNLOGGED "
: "";
$create_statement .= "CREATE ${parameter}TABLE $table_name_qt (\n" .
join( ",\n", map { " $_" } @field_defs, @constraint_defs ).
"\n)"
;
Expand Down
27 changes: 27 additions & 0 deletions t/47postgres-producer.t
Original file line number Diff line number Diff line change
Expand Up @@ -708,4 +708,31 @@ CREATE VIEW view_foo ( id, name ) AS

is($drop_view_9_1_produced, $drop_view_9_1_expected, "My DROP VIEW statement for 9.1 is correct");

{
my $table = SQL::Translator::Schema::Table->new( name => 'foo.bar', extra => { unlogged => 1 }, );
my $field = SQL::Translator::Schema::Field->new( name => 'baz',
table => $table,
data_type => 'VARCHAR',
size => 10,
default_value => 'quux',
is_auto_increment => 0,
is_nullable => 0,
is_foreign_key => 0,
is_unique => 0 );
$table->add_field($field);
my ($create, $fks) = SQL::Translator::Producer::PostgreSQL::create_table($table, { quote_table_names => q{"} });

my $expected = <<EOESQL;
--
-- Table: foo.bar
--
CREATE UNLOGGED TABLE "foo"."bar" (
"baz" character varying(10) DEFAULT 'quux' NOT NULL
)
EOESQL

$expected =~ s/\n\z//;
is($create, $expected, 'Create unlogged table works');
}

done_testing;