Skip to content

Commit

Permalink
Fall back to raw SQL for GENERATED columns in CREATE TABLE statem…
Browse files Browse the repository at this point in the history
…ents (#555)

Ensure that `CREATE TABLE` statements with generated columns are
converted to raw SQL operations; they can't currently be represented as
`Column`s in an `OpCreateTable`
  • Loading branch information
andrew-farries authored Dec 19, 2024
1 parent b65d850 commit 627b64e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/sql2pgroll/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ func convertColumnDef(tableName string, col *pgq.ColumnDef) (*migrations.Column,
if foreignKey == nil {
return nil, nil
}
case pgq.ConstrType_CONSTR_GENERATED:
// Generated columns are not supported
return nil, nil
case pgq.ConstrType_CONSTR_IDENTITY:
// Identity columns are not supported
return nil, nil
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/sql2pgroll/create_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ func TestUnconvertableCreateTableStatements(t *testing.T) {
"CREATE TABLE foo(a int CONSTRAINT foo_default DEFAULT 0)",
"CREATE TABLE foo(a int CONSTRAINT foo_null NULL)",
"CREATE TABLE foo(a int CONSTRAINT foo_notnull NOT NULL)",

// Generated columns are not supported
"CREATE TABLE foo(a int GENERATED ALWAYS AS (1) STORED)",
"CREATE TABLE foo(a int GENERATED ALWAYS AS IDENTITY)",
}

for _, sql := range tests {
Expand Down

0 comments on commit 627b64e

Please sign in to comment.