Skip to content

Commit

Permalink
feat: reset is_pushed on any change
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Mar 1, 2024
1 parent db4adb4 commit caf2f4a
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 16 deletions.
17 changes: 1 addition & 16 deletions views/003_analysis_views.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
CREATE OR REPLACE FUNCTION reset_is_pushed_before_update()
RETURNS TRIGGER AS $$
BEGIN
-- If any column other than is_pushed is changed, reset is_pushed to false.
IF NEW IS DISTINCT FROM OLD AND NEW.is_pushed IS NOT DISTINCT FROM OLD.is_pushed THEN
NEW.is_pushed = false;
END IF;

RETURN NEW;
END
$$ LANGUAGE plpgsql;

CREATE OR REPLACE TRIGGER reset_is_pushed_before_update
BEFORE UPDATE ON config_analysis
FOR EACH ROW
EXECUTE PROCEDURE reset_is_pushed_before_update();
-- Empty
2 changes: 2 additions & 0 deletions views/006_config_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ ON config_items
FOR EACH ROW
EXECUTE FUNCTION insert_config_create_update_delete_in_event_queue();

DROP VIEW IF EXISTS config_detail;

CREATE OR REPLACE VIEW config_detail AS
SELECT
ci.*,
Expand Down
11 changes: 11 additions & 0 deletions views/026_is_pushed__trigger_func.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE
OR REPLACE FUNCTION reset_is_pushed_before_update() RETURNS TRIGGER AS $$
BEGIN
-- If any column other than is_pushed is changed, reset is_pushed to false.
IF NEW IS DISTINCT FROM OLD AND NEW.is_pushed IS NOT DISTINCT FROM OLD.is_pushed THEN
NEW.is_pushed = false;
END IF;

RETURN NEW;
END
$$ LANGUAGE plpgsql;
23 changes: 23 additions & 0 deletions views/026_is_pushed_agent_canary_checker.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
DO $$
DECLARE
table_name TEXT;
BEGIN
FOR table_name IN
SELECT t.table_name
FROM information_schema.tables t
WHERE t.table_schema = current_schema() AND t.table_type = 'BASE TABLE'
AND t.table_name IN (
'canaries',
'checks',
'check_statuses'
)
LOOP
EXECUTE format('
CREATE OR REPLACE TRIGGER %I_reset_is_pushed_before_update
BEFORE UPDATE ON %I
FOR EACH ROW
EXECUTE PROCEDURE reset_is_pushed_before_update()',
table_name, table_name
);
END LOOP;
END $$;
24 changes: 24 additions & 0 deletions views/026_is_pushed_agent_config_db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
DO $$
DECLARE
table_name TEXT;
BEGIN
FOR table_name IN
SELECT t.table_name
FROM information_schema.tables t
WHERE t.table_schema = current_schema() AND t.table_type = 'BASE TABLE'
AND t.table_name IN (
'config_scrapers',
'config_items',
'config_changes',
'config_analysis'
)
LOOP
EXECUTE format('
CREATE OR REPLACE TRIGGER %I_reset_is_pushed_before_update
BEFORE UPDATE ON %I
FOR EACH ROW
EXECUTE PROCEDURE reset_is_pushed_before_update()',
table_name, table_name
);
END LOOP;
END $$;
22 changes: 22 additions & 0 deletions views/026_is_pushed_agent_mc.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
DO $$
DECLARE
table_name TEXT;
BEGIN
FOR table_name IN
SELECT t.table_name
FROM information_schema.tables t
WHERE t.table_schema = current_schema() AND t.table_type = 'BASE TABLE'
AND t.table_name IN (
'topologies'
'components'
)
LOOP
EXECUTE format('
CREATE OR REPLACE TRIGGER %I_reset_is_pushed_before_update
BEFORE UPDATE ON %I
FOR EACH ROW
EXECUTE PROCEDURE reset_is_pushed_before_update()',
table_name, table_name
);
END LOOP;
END $$;

0 comments on commit caf2f4a

Please sign in to comment.