From 92963bd7d424b8dddc80adacc18a86da9672b732 Mon Sep 17 00:00:00 2001 From: Andrew Farries Date: Wed, 17 Jan 2024 08:39:43 +0000 Subject: [PATCH] Strengthen assertions for adding CHECKs Ensure that a constraint with the expected name is present on the table. --- pkg/migrations/op_set_check_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/migrations/op_set_check_test.go b/pkg/migrations/op_set_check_test.go index 184ceab1..048a2307 100644 --- a/pkg/migrations/op_set_check_test.go +++ b/pkg/migrations/op_set_check_test.go @@ -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", @@ -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. @@ -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",