Skip to content

Commit

Permalink
Fix test expectations for ADD COLUMN SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-farries committed Dec 19, 2024
1 parent 9a04cd5 commit 20962cc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/sql2pgroll/alter_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
49 changes: 33 additions & 16 deletions pkg/sql2pgroll/expect/add_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ var AddColumnOp1 = &migrations.OpAddColumn{
Table: "foo",
Up: sql2pgroll.PlaceHolderSQL,
Column: migrations.Column{
Name: "bar",
Type: "int",
Name: "bar",
Type: "int",
Nullable: true,
},
}

var AddColumnOp2 = &migrations.OpAddColumn{
Table: "schema.foo",
Up: sql2pgroll.PlaceHolderSQL,
Column: migrations.Column{
Name: "bar",
Type: "int",
Name: "bar",
Type: "int",
Nullable: true,
},
}

Expand All @@ -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,
},
}
}
Expand All @@ -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,
},
}

Expand All @@ -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: "",
Expand All @@ -84,22 +89,34 @@ 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",
},
},
}

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",
Expand Down

0 comments on commit 20962cc

Please sign in to comment.