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; + 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 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])