diff --git a/pkg/sql2pgroll/alter_table_test.go b/pkg/sql2pgroll/alter_table_test.go index f74eace5..96f90348 100644 --- a/pkg/sql2pgroll/alter_table_test.go +++ b/pkg/sql2pgroll/alter_table_test.go @@ -148,7 +148,7 @@ func TestConvertAlterTableStatements(t *testing.T) { }, { sql: "ALTER TABLE foo ADD COLUMN bar int NOT NULL", - expectedOp: expect.AddColumnOp1, + expectedOp: expect.AddColumnOp8, }, { sql: "ALTER TABLE schema.foo ADD COLUMN bar int", diff --git a/pkg/sql2pgroll/expect/add_column.go b/pkg/sql2pgroll/expect/add_column.go index 76de2583..2df82c28 100644 --- a/pkg/sql2pgroll/expect/add_column.go +++ b/pkg/sql2pgroll/expect/add_column.go @@ -11,8 +11,9 @@ var AddColumnOp1 = &migrations.OpAddColumn{ Table: "foo", Up: sql2pgroll.PlaceHolderSQL, Column: migrations.Column{ - Name: "bar", - Type: "int", + Name: "bar", + Type: "int", + Nullable: true, }, } @@ -20,8 +21,9 @@ var AddColumnOp2 = &migrations.OpAddColumn{ Table: "schema.foo", Up: sql2pgroll.PlaceHolderSQL, Column: migrations.Column{ - Name: "bar", - Type: "int", + Name: "bar", + Type: "int", + Nullable: true, }, } @@ -30,9 +32,10 @@ func AddColumnOp1WithDefault(def *string) *migrations.OpAddColumn { Table: "foo", Up: sql2pgroll.PlaceHolderSQL, Column: migrations.Column{ - Name: "bar", - Type: "int", - Default: def, + Name: "bar", + Type: "int", + Default: def, + Nullable: true, }, } } @@ -51,9 +54,10 @@ var AddColumnOp4 = &migrations.OpAddColumn{ Table: "foo", Up: sql2pgroll.PlaceHolderSQL, Column: migrations.Column{ - Name: "bar", - Type: "int", - Unique: true, + Name: "bar", + Type: "int", + Unique: true, + Nullable: true, }, } @@ -71,8 +75,9 @@ var AddColumnOp6 = &migrations.OpAddColumn{ Table: "foo", Up: sql2pgroll.PlaceHolderSQL, Column: migrations.Column{ - Name: "bar", - Type: "int", + Name: "bar", + Type: "int", + Nullable: true, Check: &migrations.CheckConstraint{ Constraint: "bar > 0", Name: "", @@ -84,8 +89,9 @@ var AddColumnOp7 = &migrations.OpAddColumn{ Table: "foo", Up: sql2pgroll.PlaceHolderSQL, Column: migrations.Column{ - Name: "bar", - Type: "int", + Name: "bar", + Type: "int", + Nullable: true, Check: &migrations.CheckConstraint{ Constraint: "bar > 0", Name: "check_bar", @@ -93,13 +99,24 @@ var AddColumnOp7 = &migrations.OpAddColumn{ }, } +var AddColumnOp8 = &migrations.OpAddColumn{ + Table: "foo", + Up: sql2pgroll.PlaceHolderSQL, + Column: migrations.Column{ + Name: "bar", + Type: "int", + Nullable: false, + }, +} + func AddColumnOp8WithOnDeleteAction(action migrations.ForeignKeyReferenceOnDelete) *migrations.OpAddColumn { return &migrations.OpAddColumn{ Table: "foo", Up: sql2pgroll.PlaceHolderSQL, Column: migrations.Column{ - Name: "bar", - Type: "int", + Name: "bar", + Type: "int", + Nullable: true, References: &migrations.ForeignKeyReference{ Column: "bar", Name: "fk_baz",