Skip to content
Permalink
Browse files
Only execute trigger to set closed_utc after state changed
  • Loading branch information
ad-si committed Mar 1, 2020
1 parent 10f8cf6 commit 395a8e0ecae0810cf7c5eb61231a696524f82c08
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
@@ -59,9 +59,11 @@ createTriggerClosed :: Connection -> IO (Doc ann)
createTriggerClosed connection =
S.createWithQuery connection $
S.createTriggerAfterUpdate "set_closed_utc" "tasks"
"(new.state is 'Done'\n\
"old.state is not new.state and (\n\
\new.state is 'Done'\n\
\or new.state is 'Obsolete'\n\
\or new.state is 'Deletable')"
\or new.state is 'Deletable'\n\
\)"
"\
\update tasks\n\
\set closed_utc = datetime('now')\n\
@@ -162,6 +162,20 @@ _3_ =
}


-- | Fixes activation condition of task closed trigger.
-- | FIXME: This empty migration is a hack to run an update of all triggers.
_4_ :: MigrateDirection -> Migration
_4_ =
let
base = Migration
{ id = UserVersion 4
, querySet = []
}
in \case
MigrateUp -> base { Migrations.querySet = [] }
MigrateDown -> base { Migrations.querySet = [] }


hasDuplicates :: Eq a => [a] -> Bool
hasDuplicates [] = False
hasDuplicates (x:xs) =
@@ -221,6 +235,7 @@ runMigrations conf connection = do
_1_ :
_2_ :
_3_ :
_4_ :
[])

migrationsUp = fmap ($ MigrateUp) migrations

0 comments on commit 395a8e0

Please sign in to comment.