server: add unique constraints to the cron events table (#1131)

GitOrigin-RevId: 3939001a90de041d588c4133ecc1b28b35734d72
This commit is contained in:
Karthikeyan Chinnakonda 2021-04-15 16:51:05 +05:30 committed by hasura-bot
parent 8222651c4b
commit 2d9959b174
4 changed files with 13 additions and 1 deletions

View File

@ -1 +1 @@
45
46

View File

@ -61,6 +61,10 @@ CREATE TABLE hdb_catalog.hdb_cron_events
CREATE INDEX hdb_cron_event_status ON hdb_catalog.hdb_cron_events (status);
CREATE UNIQUE INDEX hdb_cron_events_unique_scheduled ON
hdb_catalog.hdb_cron_events (trigger_name, scheduled_time)
where status = 'scheduled';
CREATE TABLE hdb_catalog.hdb_cron_event_invocation_logs
(
id TEXT DEFAULT hdb_catalog.gen_hasura_uuid() PRIMARY KEY,

View File

@ -0,0 +1,7 @@
-- This index is added to avoid creating duplicate cron
-- events when multiple Hasura instances are running.
-- This is a partial index for backwards compatibility i.e.
-- the metadata db might already have duplicated events before this change was added.
CREATE UNIQUE INDEX hdb_cron_events_unique_scheduled
ON hdb_catalog.hdb_cron_events (trigger_name, scheduled_time)
WHERE status = 'scheduled';

View File

@ -0,0 +1 @@
DROP INDEX hdb_catalog.hdb_cron_events_unique_scheduled;