From 8fe4b50c20f247d4d830451057061bd45d222a40 Mon Sep 17 00:00:00 2001 From: Marcelo Zabani Date: Mon, 6 Apr 2026 13:30:30 -0300 Subject: [PATCH 1/3] I consider this a bug in our tests, so fixing it I think postgresql-simple allows this due to its `FromField a => FromRow [a]` instance when `a ~ Char`. We were only checking results against an empty list, so this never had a chance to fail. --- test/DbDependentSpecs/BackgroundJobsSpec.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/DbDependentSpecs/BackgroundJobsSpec.hs b/test/DbDependentSpecs/BackgroundJobsSpec.hs index c144434f..0efcc5f0 100644 --- a/test/DbDependentSpecs/BackgroundJobsSpec.hs +++ b/test/DbDependentSpecs/BackgroundJobsSpec.hs @@ -219,7 +219,7 @@ spec = do lastRunAt startedCoddJob `shouldNotBe` Nothing completedOrAbortedAt startedCoddJob `shouldBe` Nothing finalizedAt startedCoddJob `shouldBe` Nothing - (allEmployees :: [(String, String)], finalizedCoddJob :: JobInfo, scheduledCronJobs :: [String]) <- + (allEmployees :: [(String, String)], finalizedCoddJob :: JobInfo, scheduledCronJobs :: [DB.Only String]) <- applyMigrationsNoCheck testDbInfo {txnIsolationLvl = txnIsolationLvl} (Just [finalizeExperienceMigration]) @@ -274,7 +274,7 @@ spec = do -- it to conflict with itself. -- The call to applyMigrationsNoCheck below deadlocks unless codd's schema has carefully designed locks -- in its functions. - (allEmployees :: [(String, String)], finalizedCoddJob :: JobInfo, scheduledCronJobs :: [String]) <- + (allEmployees :: [(String, String)], finalizedCoddJob :: JobInfo, scheduledCronJobs :: [DB.Only String]) <- applyMigrationsNoCheck testDbInfo {txnIsolationLvl = txnIsolationLvl} (Just [finalizeExperienceMigration]) From 5c96ee6ce489f52122ba9289a70c469edc79059c Mon Sep 17 00:00:00 2001 From: Marcelo Zabani Date: Sun, 12 Apr 2026 15:07:05 -0300 Subject: [PATCH 2/3] Fix race condition with notifications --- src/Codd/AppCommands/AddMigration.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Codd/AppCommands/AddMigration.hs b/src/Codd/AppCommands/AddMigration.hs index f2fabc95..e346366a 100644 --- a/src/Codd/AppCommands/AddMigration.hs +++ b/src/Codd/AppCommands/AddMigration.hs @@ -212,8 +212,12 @@ addMigration dbInfo@Codd.CoddSettings {onDiskReps, migsConnString = defaultConnI (pgMajorVer, _) <- queryServerMajorAndFullVersion conn (pgMajorVer,) <$> readRepresentationsFromDbWithSettings dbInfo conn ) - addedMigRequiresCoddSchema <- liftIO $ checkCoddSchemaFunctionsHaveBeenCalled listenConn + -- Different connections means different sockets, which means we have to fetch + -- some query results _before_ `checkCoddSchemaFunctionsHaveBeenCalled`, because + -- that checks if a notification was received non-blocking, and that can return + -- no notifications unless we fetch something on "listenConn" first. newlyStartedJobs <- getAddedJobsStillRunning listenConn maxBackgroundJobIdBefore + addedMigRequiresCoddSchema <- liftIO $ checkCoddSchemaFunctionsHaveBeenCalled listenConn closeFileStream migStream pure (pgVerAndSchemas, addedMigRequiresCoddSchema, newlyStartedJobs) persistRepsToDisk pgMajorVer databaseSchemas onDiskRepsDir From 01604aed9ee77fb606a754859ff34681749a30d0 Mon Sep 17 00:00:00 2001 From: Marcelo Zabani Date: Sun, 12 Apr 2026 15:15:11 -0300 Subject: [PATCH 3/3] Make one migration have CRLF line endings --- .../2024-07-16-00-33-13-create-statistics.sql | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/sql-migrations/all/2024-07-16-00-33-13-create-statistics.sql b/sql-migrations/all/2024-07-16-00-33-13-create-statistics.sql index 53b9759f..e3c7738a 100644 --- a/sql-migrations/all/2024-07-16-00-33-13-create-statistics.sql +++ b/sql-migrations/all/2024-07-16-00-33-13-create-statistics.sql @@ -1,11 +1,13 @@ -CREATE STATISTICS IF NOT EXISTS test_stat_expr - ( dependencies,mcv) ON employee_id, lower(employee_name) - FROM employee ; -CREATE STATISTICS IF NOT EXISTS test_stat - ( dependencies,ndistinct,mcv) ON employee_id, employee_name - FROM employee ; - -CREATE STATISTICS IF NOT EXISTS test_stat_with_expr - ( dependencies,ndistinct,mcv) ON id, (lower(popular_name)), popular_name, (id*42) - FROM animals; - +-- This file has CRLF line endings, just another test +-- +CREATE STATISTICS IF NOT EXISTS test_stat_expr + ( dependencies,mcv) ON employee_id, lower(employee_name) + FROM employee ; +CREATE STATISTICS IF NOT EXISTS test_stat + ( dependencies,ndistinct,mcv) ON employee_id, employee_name + FROM employee ; + +CREATE STATISTICS IF NOT EXISTS test_stat_with_expr + ( dependencies,ndistinct,mcv) ON id, (lower(popular_name)), popular_name, (id*42) + FROM animals; +