Skip to content

Commit ef7cf14

Browse files
Fall back to raw SQL for GENERATED columns
Ensure that `CREATE TABLE` statements with generated columns are converted to raw SQL.
1 parent 68ef5c4 commit ef7cf14

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pkg/sql2pgroll/create_table.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ func convertColumnDef(tableName string, col *pgq.ColumnDef) (*migrations.Column,
139139
if foreignKey == nil {
140140
return nil, nil
141141
}
142+
case pgq.ConstrType_CONSTR_GENERATED:
143+
// Generated columns are not supported
144+
return nil, nil
145+
case pgq.ConstrType_CONSTR_IDENTITY:
146+
// Identity columns are not supported
147+
return nil, nil
142148
}
143149
}
144150

pkg/sql2pgroll/create_table_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ func TestUnconvertableCreateTableStatements(t *testing.T) {
199199
"CREATE TABLE foo(a int CONSTRAINT foo_default DEFAULT 0)",
200200
"CREATE TABLE foo(a int CONSTRAINT foo_null NULL)",
201201
"CREATE TABLE foo(a int CONSTRAINT foo_notnull NOT NULL)",
202+
203+
// Generated columns are not supported
204+
"CREATE TABLE foo(a int GENERATED ALWAYS AS (1) STORED)",
205+
"CREATE TABLE foo(a int GENERATED ALWAYS AS IDENTITY)",
202206
}
203207

204208
for _, sql := range tests {

0 commit comments

Comments
 (0)