summaryrefslogtreecommitdiff
path: root/Omni/Task/MigrationTest.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bensima.com>2025-11-27 15:21:18 -0500
committerBen Sima <ben@bensima.com>2025-11-27 15:26:30 -0500
commit39791b4552b605fe60d03a5e98c5533bd741b729 (patch)
tree0b7d34a1d9cfb205dc8c5a9da13c94f1531c5cac /Omni/Task/MigrationTest.hs
parent15068f1e736288c2d782eada8e24d71375f9ffef (diff)
Fix SQL query and add simple migration test
Diffstat (limited to 'Omni/Task/MigrationTest.hs')
-rw-r--r--Omni/Task/MigrationTest.hs42
1 files changed, 42 insertions, 0 deletions
diff --git a/Omni/Task/MigrationTest.hs b/Omni/Task/MigrationTest.hs
new file mode 100644
index 0000000..f16f782
--- /dev/null
+++ b/Omni/Task/MigrationTest.hs
@@ -0,0 +1,42 @@
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE NoImplicitPrelude #-}
+
+module Omni.Task.MigrationTest where
+
+import Alpha
+import qualified Data.Set as Set
+import Omni.Task.Core
+import qualified Omni.Test as Test
+import System.Directory (doesFileExist, removeFile)
+import System.Environment (setEnv)
+
+test :: Test.Tree
+test = Test.group "Omni.Task.Migration" [migrationStartupTest]
+
+migrationStartupTest :: Test.Tree
+migrationStartupTest =
+ Test.unit "database initializes with schema migrations" <| do
+ setEnv "TASK_TEST_MODE" "1"
+
+ let testFile = "_/tmp/tasks-test.db"
+ exists <- doesFileExist testFile
+ when exists <| removeFile testFile
+
+ initTaskDb
+
+ withDb <| \conn -> do
+ tasksCols <- getTableColumns conn "tasks"
+ activityCols <- getTableColumns conn "task_activity"
+ retryCols <- getTableColumns conn "retry_context"
+
+ Set.fromList ["id", "title", "status"]
+ `Set.isSubsetOf` Set.fromList tasksCols
+ Test.@?= True
+ Set.fromList ["id", "task_id", "stage"]
+ `Set.isSubsetOf` Set.fromList activityCols
+ Test.@?= True
+ Set.fromList ["task_id", "attempt", "reason"]
+ `Set.isSubsetOf` Set.fromList retryCols
+ Test.@?= True
+
+ removeFile testFile