Skip to content

Commit

Permalink
Strengthen assertions for adding CHECKs
Browse files Browse the repository at this point in the history
Ensure that a constraint with the expected name is present on the table.
  • Loading branch information
andrew-farries committed Jan 17, 2024
1 parent 684d324 commit 92963bd
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/migrations/op_set_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func TestSetCheckConstraint(t *testing.T) {
// The new (temporary) `title` column should exist on the underlying table.
ColumnMustExist(t, db, "public", "posts", migrations.TemporaryName("title"))

// A check constraint has been added to the temporary column
ConstraintMustExist(t, db, "public", "posts", "check_title_length")

// Inserting a row that meets the check constraint into the old view works.
MustInsert(t, db, "public", "01_add_table", "posts", map[string]string{
"title": "post by alice",
Expand Down Expand Up @@ -96,6 +99,9 @@ func TestSetCheckConstraint(t *testing.T) {
// The new (temporary) `title` column should not exist on the underlying table.
ColumnMustNotExist(t, db, "public", "posts", migrations.TemporaryName("title"))

// The check constraint no longer exists.
ConstraintMustNotExist(t, db, "public", "posts", "check_title_length")

// The up function no longer exists.
FunctionMustNotExist(t, db, "public", migrations.TriggerFunctionName("posts", "title"))
// The down function no longer exists.
Expand All @@ -107,6 +113,9 @@ func TestSetCheckConstraint(t *testing.T) {
TriggerMustNotExist(t, db, "public", "posts", migrations.TriggerName("posts", migrations.TemporaryName("title")))
},
afterComplete: func(t *testing.T, db *sql.DB) {
// The check constraint exists on the new table.
ConstraintMustExist(t, db, "public", "posts", "check_title_length")

// Inserting a row that meets the check constraint into the new view works.
MustInsert(t, db, "public", "02_add_check_constraint", "posts", map[string]string{
"title": "post by dana",
Expand Down

0 comments on commit 92963bd

Please sign in to comment.