Skip to content
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
22 changes: 9 additions & 13 deletions .vscode/mcp.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"inputs": [
{
"type": "promptString",
"id": "supabase-access-token",
"description": "Supabase personal access token",
"password": true
}
],
"servers": {
"supabase": {
"command": "npx",
Expand All @@ -10,18 +18,6 @@
"SUPABASE_ACCESS_TOKEN": "${input:supabase-access-token}"
},
"type": "stdio"
},
"SVELTEKIT-mcp-server-70cd8977": {
"url": "https://mcp.svelte.dev/mcp",
"type": "http"
}
},
"inputs": [
{
"type": "promptString",
"id": "supabase-access-token",
"description": "Supabase personal access token",
"password": true
}
]
}
}
34 changes: 34 additions & 0 deletions SUPABAES_SETUP_SCRIPTS/TRIGGERS/alert_triggered_insert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
CREATE OR REPLACE FUNCTION public.fn_log_rule_trigger()
RETURNS trigger
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = public
AS $$
BEGIN
-- Only handle rising edge: false -> true
IF COALESCE(OLD.is_triggered, false) = false
AND COALESCE(NEW.is_triggered, false) = true
THEN
-- -- Stamp and bump (commented out for now)
-- NEW.last_triggered := (now() AT TIME ZONE 'utc');
-- NEW.trigger_count := COALESCE(OLD.trigger_count, 0) + 1;

-- Insert log row if we have both NOT NULL values required by FK
IF NEW.dev_eui IS NOT NULL AND NEW."ruleGroupId" IS NOT NULL THEN
INSERT INTO public.cw_rule_triggered (dev_eui, rule_group_id)
VALUES (NEW.dev_eui, NEW."ruleGroupId");
END IF;
END IF;

RETURN NEW;
END;
$$;


DROP TRIGGER IF EXISTS trg_cw_rules_log_trigger ON public.cw_rules;

CREATE TRIGGER trg_cw_rules_log_trigger
BEFORE UPDATE OF is_triggered ON public.cw_rules
FOR EACH ROW
WHEN (COALESCE(OLD.is_triggered, false) IS DISTINCT FROM COALESCE(NEW.is_triggered, false))
EXECUTE FUNCTION public.fn_log_rule_trigger();
Loading