nidus-sync/db/migrations/00110_job.sql
Eli Ribble 1e071d5ce5
Overhaul publicreport storage layer, create unified tables
This is a huge change. I was getting really sick of the split between
nuisance/water tables when more than half of the data they store is
common. I finally bit off the big work of switching it all.

This creates a single unified table, publicreport.report and copies the
existing report data into it. It also ports existing data from the
original tables into the new table.

Along with all of this I also overhauled the system for handling
asynchronous work to use a LISTEN/NOTIFY connection from the database
and a single cache table to avoid ever losing work.
2026-03-18 15:36:20 +00:00

41 lines
1 KiB
PL/PgSQL

-- +goose Up
CREATE TYPE JobType AS ENUM (
'audio-transcode',
'csv-commit',
'csv-import',
'label-studio-audio-create',
'email-send',
'text-respond',
'text-send'
);
ALTER TYPE comms.TextJobType ADD VALUE 'report-message' AFTER 'report-confirmation';
CREATE TABLE job (
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
id SERIAL NOT NULL,
type_ JobType NOT NULL,
row_id INTEGER NOT NULL,
PRIMARY KEY(id)
);
COMMENT ON TABLE job IS 'A temporary holding place for jobs that are pushed to backend workers. Once work is completed the job should be deleted';
-- +goose StatementBegin
CREATE OR REPLACE FUNCTION notify_new_job()
RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify('new_job', NEW.id::text);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
-- +goose StatementEnd
CREATE TRIGGER job_insert_trigger
AFTER INSERT ON job
FOR EACH ROW
EXECUTE FUNCTION notify_new_job();
-- +goose Down
DROP TRIGGER job_insert_trigger ON job;
DROP TABLE job;
-- ALTER TYPE comms.TextJobType DROP VALUE 'report-message';
DROP TYPE JobType;