From bcb4802a11b6ada93b3b6cb62deaa924d52590b8 Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Wed, 18 Dec 2024 08:22:46 +0000 Subject: [PATCH] Fall back to raw SQL for `TABLESPACE` clause Tablespace options are not representable as an `OpCreateTable` operation. --- pkg/sql2pgroll/create_table.go | 3 +++ pkg/sql2pgroll/create_table_test.go | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/sql2pgroll/create_table.go b/pkg/sql2pgroll/create_table.go index fd862a4c..4ea6baea 100644 --- a/pkg/sql2pgroll/create_table.go +++ b/pkg/sql2pgroll/create_table.go @@ -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 } diff --git a/pkg/sql2pgroll/create_table_test.go b/pkg/sql2pgroll/create_table_test.go index 1417daf4..62388a0f 100644 --- a/pkg/sql2pgroll/create_table_test.go +++ b/pkg/sql2pgroll/create_table_test.go @@ -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 @@ -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 {