diff --git a/docs/postgres-planning.md b/docs/postgres-planning.md index e24b9a6..feac5de 100644 --- a/docs/postgres-planning.md +++ b/docs/postgres-planning.md @@ -41,6 +41,7 @@ CREATE TABLE hashes ( motion_identifier TEXT, ); + CREATE TABLE variants ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), hash BYTEA REFERENCES hashes(hash) ON DELETE CASCADE, @@ -48,6 +49,7 @@ CREATE TABLE variants ( identifier TEXT NOT NULL ); + CREATE UNIQUE INDEX hash_variant_index ON variants (hash, variant); ``` @@ -133,6 +135,7 @@ methods: ```sql CREATE TYPE job_status AS ENUM ('new', 'running'); + CREATE TABLE queue ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), queue VARCHAR(30) NOT NULL, @@ -142,6 +145,7 @@ CREATE TABLE queue ( queue_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ); + CREATE INDEX queue_worker_id_index ON queue INCLUDE worker_id; CREATE INDEX queue_status_index ON queue INCLUDE status; ``` @@ -150,6 +154,7 @@ claiming a job can be ```sql DELETE FROM queue WHERE worker_id = '$WORKER_ID'; + UPDATE queue SET status = 'running', worker_id = '$WORKER_ID' WHERE id = ( SELECT id @@ -162,6 +167,25 @@ WHERE id = ( returning *; ``` +notifying pict-rs of a ready job could be +```sql +CREATE OR REPLACE FUNCTION queue_status_notify() + RETURNS trigger AS +$$ +BEGIN + PERFORM pg_notify('queue_status_channel', NEW.id::text); + RETURN NEW; +END; +$$ LANGUAGE plpgsql; + + +CREATE TRIGGER queue_status + AFTER INSERT OR UPDATE OF status + ON queue + FOR EACH ROW +EXECUTE PROCEDURE queue_status_notify(); +``` + ### MigrationRepo This is used for migrating from local storage to object storage. It keeps track of which identifiers