Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BCF-2880 remove unused db funcs and triggers #11730

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading