Skip to content

Commit

Permalink
Fall back to raw SQL for TABLESPACE clause
Browse files Browse the repository at this point in the history
Tablespace options are not representable as an `OpCreateTable`
operation.
  • Loading branch information
andrew-farries committed Dec 18, 2024
1 parent a0fceb5 commit bcb4802
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/sql2pgroll/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func canConvertCreateStatement(stmt *pgq.CreateStmt) bool {
// ON COMMIT options are not supported
case stmt.GetOncommit() != pgq.OnCommitAction_ONCOMMIT_NOOP:
return false
// Setting a tablespace is not supported
case stmt.GetTablespacename() != "":
return false
default:
return true
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/sql2pgroll/create_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ func TestUnconvertableCreateTableStatements(t *testing.T) {
t.Parallel()

tests := []string{
// CREATE TABLE options that are not representable as `pgroll` operations.
// Temporary and unlogged tables are not supported
"CREATE TEMPORARY TABLE foo(a int)",
"CREATE UNLOGGED TABLE foo(a int)",

// The IF NOT EXISTS clause is not supported
"CREATE TABLE IF NOT EXISTS foo(a int)",

// Table inheritance is not supported
"CREATE TABLE foo(a int) INHERITS (bar)",

// Any kind of partitioning is not supported
Expand All @@ -97,6 +101,9 @@ func TestUnconvertableCreateTableStatements(t *testing.T) {
// valid for all tables, but Postgres will reject them for non-temporary
// tables. We err on the side of caution and reject them for all tables.
"CREATE TABLE foo(a int) ON COMMIT DROP",

// Specifying a tablespace is not supported
"CREATE TABLE foo(a int) TABLESPACE bar",
}

for _, sql := range tests {
Expand Down

0 comments on commit bcb4802

Please sign in to comment.