Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow INITIALLY IMMEDIATE constraints in CREATE TABLE statements #560

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions pkg/sql2pgroll/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,11 @@ func convertColumnDef(tableName string, col *pgq.ColumnDef) (*migrations.Column,
if foreignKey == nil {
return nil, nil
}
case pgq.ConstrType_CONSTR_ATTR_NOT_DEFERRABLE:
// NOT DEFERRABLE constraints are the default and are supported, but no
// extra annotation is needed
case
pgq.ConstrType_CONSTR_ATTR_NOT_DEFERRABLE,
pgq.ConstrType_CONSTR_ATTR_IMMEDIATE:
// NOT DEFERRABLE and INITIALLY IMMEDIATE constraints are the default and
// are supported, but no extra annotation is needed
continue
case pgq.ConstrType_CONSTR_GENERATED:
// Generated columns are not supported
Expand All @@ -163,9 +165,6 @@ func convertColumnDef(tableName string, col *pgq.ColumnDef) (*migrations.Column,
case pgq.ConstrType_CONSTR_ATTR_DEFERRABLE:
// Deferrable constraints are not supported
return nil, nil
case pgq.ConstrType_CONSTR_ATTR_IMMEDIATE:
// Initially immediate deferred constraints are not supported
return nil, nil
case pgq.ConstrType_CONSTR_ATTR_DEFERRED:
// Initially deferred deferred constraints are not supported
return nil, nil
Expand Down
12 changes: 12 additions & 0 deletions pkg/sql2pgroll/create_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func TestConvertCreateTableStatements(t *testing.T) {
sql: "CREATE TABLE foo(a int UNIQUE NOT DEFERRABLE)",
expectedOp: expect.CreateTableOp5,
},
{
sql: "CREATE TABLE foo(a int UNIQUE INITIALLY IMMEDIATE)",
expectedOp: expect.CreateTableOp5,
},
{
sql: "CREATE TABLE foo(a int PRIMARY KEY)",
expectedOp: expect.CreateTableOp6,
Expand All @@ -52,6 +56,10 @@ func TestConvertCreateTableStatements(t *testing.T) {
sql: "CREATE TABLE foo(a int PRIMARY KEY NOT DEFERRABLE)",
expectedOp: expect.CreateTableOp6,
},
{
sql: "CREATE TABLE foo(a int PRIMARY KEY INITIALLY IMMEDIATE)",
expectedOp: expect.CreateTableOp6,
},
{
sql: "CREATE TABLE foo(a int CHECK (a > 0))",
expectedOp: expect.CreateTableOp10,
Expand All @@ -76,6 +84,10 @@ func TestConvertCreateTableStatements(t *testing.T) {
sql: "CREATE TABLE foo(a int REFERENCES bar(b) NOT DEFERRABLE)",
expectedOp: expect.CreateTableOp12,
},
{
sql: "CREATE TABLE foo(a int REFERENCES bar(b) INITIALLY IMMEDIATE)",
expectedOp: expect.CreateTableOp12,
},
{
sql: "CREATE TABLE foo(a int REFERENCES bar(b) ON UPDATE NO ACTION)",
expectedOp: expect.CreateTableOp12,
Expand Down