Skip to content

Commit

Permalink
test: Change column type preserves NOT NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-farries committed Jan 22, 2024
1 parent 3d4a177 commit b68cdb9
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions pkg/migrations/op_change_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,57 @@ func TestChangeColumnType(t *testing.T) {
}, testutils.CheckViolationErrorCode)
},
},
{
name: "changing column type preserves column not null",
migrations: []migrations.Migration{
{
Name: "01_add_table",
Operations: migrations.Operations{
&migrations.OpCreateTable{
Name: "users",
Columns: []migrations.Column{
{
Name: "id",
Type: "integer",
Pk: true,
},
{
Name: "username",
Type: "text",
Nullable: false,
},
},
},
},
},
{
Name: "02_change_type",
Operations: migrations.Operations{
&migrations.OpAlterColumn{
Table: "users",
Column: "username",
Type: "varchar(255)",
Up: "username",
Down: "username",
},
},
},
},
afterStart: func(t *testing.T, db *sql.DB) {
// Inserting a row that violates the NOT NULL constraint fails.
MustNotInsert(t, db, "public", "02_change_type", "users", map[string]string{
"id": "1",
}, testutils.NotNullViolationErrorCode)
},
afterRollback: func(t *testing.T, db *sql.DB) {
},
afterComplete: func(t *testing.T, db *sql.DB) {
// Inserting a row that violates the NOT NULL constraint fails.
MustNotInsert(t, db, "public", "02_change_type", "users", map[string]string{
"id": "2",
}, testutils.NotNullViolationErrorCode)
},
},
})
}

Expand Down

0 comments on commit b68cdb9

Please sign in to comment.