Skip to content

Commit

Permalink
BCF-2880 remove unused db funcs and triggers (#11730)
Browse files Browse the repository at this point in the history
  • Loading branch information
krehermann authored Jan 10, 2024
1 parent e8c68bd commit c1eeb28
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- +goose Up

-- +goose StatementBegin
DROP FUNCTION IF EXISTS PUBLIC.check_terra_msg_state_transition;
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin

CREATE OR REPLACE FUNCTION PUBLIC.check_terra_msg_state_transition() RETURNS TRIGGER AS $$
DECLARE
state_transition_map jsonb := json_build_object(
'unstarted', json_build_object('errored', true, 'started', true),
'started', json_build_object('errored', true, 'broadcasted', true),
'broadcasted', json_build_object('errored', true, 'confirmed', true));
BEGIN
IF NOT state_transition_map ? OLD.state THEN
RAISE EXCEPTION 'Invalid from state %. Valid from states %', OLD.state, state_transition_map;
END IF;
IF NOT state_transition_map->OLD.state ? NEW.state THEN
RAISE EXCEPTION 'Invalid state transition from % to %. Valid to states %', OLD.state, NEW.state, state_transition_map->OLD.state;
END IF;
RETURN NEW;
END
$$ LANGUAGE plpgsql;

-- +goose StatementEnd
48 changes: 48 additions & 0 deletions core/store/migrate/migrations/0217_drop_unused_job_triggers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-- +goose Up
-- +goose StatementBegin
DROP TRIGGER IF EXISTS notify_job_created ON PUBLIC.jobs;
DROP FUNCTION IF EXISTS PUBLIC.notifyjobcreated();

DROP TRIGGER IF EXISTS notify_job_deleted ON PUBLIC.jobs;
DROP FUNCTION IF EXISTS PUBLIC.notifyjobdeleted();

DROP TRIGGER IF EXISTS notify_pipeline_run_started ON PUBLIC.pipeline_runs;
DROP FUNCTION IF EXISTS PUBLIC.notifypipelinerunstarted();
-- +goose StatementEnd


-- +goose Down
-- +goose StatementBegin
CREATE FUNCTION PUBLIC.notifyjobcreated() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
PERFORM pg_notify('insert_on_jobs', NEW.id::text);
RETURN NEW;
END
$$;
CREATE TRIGGER notify_job_created AFTER INSERT ON PUBLIC.jobs FOR EACH ROW EXECUTE PROCEDURE PUBLIC.notifyjobcreated();

CREATE FUNCTION PUBLIC.notifyjobdeleted() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
PERFORM pg_notify('delete_from_jobs', OLD.id::text);
RETURN OLD;
END
$$;
CREATE TRIGGER notify_job_deleted AFTER DELETE ON PUBLIC.jobs FOR EACH ROW EXECUTE PROCEDURE PUBLIC.notifyjobdeleted();

CREATE FUNCTION PUBLIC.notifypipelinerunstarted() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
IF NEW.finished_at IS NULL THEN
PERFORM pg_notify('pipeline_run_started', NEW.id::text);
END IF;
RETURN NEW;
END
$$;
CREATE TRIGGER notify_pipeline_run_started AFTER INSERT ON PUBLIC.pipeline_runs FOR EACH ROW EXECUTE PROCEDURE PUBLIC.notifypipelinerunstarted();

-- +goose StatementEnd

0 comments on commit c1eeb28

Please sign in to comment.