Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 395a8e0

Browse files
committed
Only execute trigger to set closed_utc after state changed
1 parent 10f8cf6 commit 395a8e0

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

tasklite-core/source/DbSetup.hs

+4-2
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ createTriggerClosed :: Connection -> IO (Doc ann)
5959
createTriggerClosed connection =
6060
S.createWithQuery connection $
6161
S.createTriggerAfterUpdate "set_closed_utc" "tasks"
62-
"(new.state is 'Done'\n\
62+
"old.state is not new.state and (\n\
63+
\new.state is 'Done'\n\
6364
\or new.state is 'Obsolete'\n\
64-
\or new.state is 'Deletable')"
65+
\or new.state is 'Deletable'\n\
66+
\)"
6567
"\
6668
\update tasks\n\
6769
\set closed_utc = datetime('now')\n\

tasklite-core/source/Migrations.hs

+15
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,20 @@ _3_ =
162162
}
163163

164164

165+
-- | Fixes activation condition of task closed trigger.
166+
-- | FIXME: This empty migration is a hack to run an update of all triggers.
167+
_4_ :: MigrateDirection -> Migration
168+
_4_ =
169+
let
170+
base = Migration
171+
{ id = UserVersion 4
172+
, querySet = []
173+
}
174+
in \case
175+
MigrateUp -> base { Migrations.querySet = [] }
176+
MigrateDown -> base { Migrations.querySet = [] }
177+
178+
165179
hasDuplicates :: Eq a => [a] -> Bool
166180
hasDuplicates [] = False
167181
hasDuplicates (x:xs) =
@@ -221,6 +235,7 @@ runMigrations conf connection = do
221235
_1_ :
222236
_2_ :
223237
_3_ :
238+
_4_ :
224239
[])
225240

226241
migrationsUp = fmap ($ MigrateUp) migrations

0 commit comments

Comments
 (0)