From edd1cd94b47876b2e06884f709e7ad00dc59439e Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Fri, 20 Dec 2024 16:39:13 +0000 Subject: [PATCH] Fall back to raw SQL for indexes created with ONLY --- pkg/sql2pgroll/create_index.go | 5 +++++ pkg/sql2pgroll/create_index_test.go | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/sql2pgroll/create_index.go b/pkg/sql2pgroll/create_index.go index 797e19e51..3637a0537 100644 --- a/pkg/sql2pgroll/create_index.go +++ b/pkg/sql2pgroll/create_index.go @@ -96,6 +96,11 @@ func canConvertCreateIndexStmt(stmt *pgq.IndexStmt) bool { if stmt.GetIndexIncludingParams() != nil { return false } + // Indexes created with ONLY are not supported + if !stmt.GetRelation().GetInh() { + return false + } + for _, param := range stmt.GetIndexParams() { if param.GetIndexElem().GetCollation() != nil { return false diff --git a/pkg/sql2pgroll/create_index_test.go b/pkg/sql2pgroll/create_index_test.go index a62e476a8..1c7ed07d5 100644 --- a/pkg/sql2pgroll/create_index_test.go +++ b/pkg/sql2pgroll/create_index_test.go @@ -142,8 +142,8 @@ func TestUnconvertableCreateIndexStatements(t *testing.T) { // opclasses with or without options are not supported "CREATE INDEX idx_name ON foo (bar opclass (test = test))", "CREATE INDEX idx_name ON foo (bar opclass)", - // TODO: Can't figure out how to detect this case - //"CREATE INDEX idx_name ON ONLY foo (bar)", + // Indexes created with ONLY are not supported + "CREATE INDEX idx_name ON ONLY foo (bar)", } for _, sql := range tests {