refactor CancelSession and updateStates to be idempotent (#390)

This commit is contained in:
Jim authored and GitHub committed 2020-09-21 11:14:30 -04:00
1 parent 72de1a6916
commit b334aeff41
3 files changed
+61 -17

No files matched your search

+21
View File
@@ -18,6 +18,27 @@ with not_active as (
select * from not_active;
`
// updateSessionState checks that we don't already have a row for the new
// state before inserting a new state.
updateSessionState = `
insert into session_state(session_id, state)
select
$1::text, $2
from
session s
where
s.public_id = $1::text and
s.public_id not in (
select
session_id
from
session_state
where
session_id = $1::text and
state = $2
)
`
terminateSessionCte = `
insert into session_state
with terminated as (