diff --git a/backend/migrations/20250902085503_notify_resource_cache_on_variable_change.down.sql b/backend/migrations/20250902085503_notify_resource_cache_on_variable_change.down.sql new file mode 100644 index 0000000000..d2f607c5b8 --- /dev/null +++ b/backend/migrations/20250902085503_notify_resource_cache_on_variable_change.down.sql @@ -0,0 +1 @@ +-- Add down migration script here diff --git a/backend/migrations/20250902085503_notify_resource_cache_on_variable_change.up.sql b/backend/migrations/20250902085503_notify_resource_cache_on_variable_change.up.sql new file mode 100644 index 0000000000..1ee9d2d43b --- /dev/null +++ b/backend/migrations/20250902085503_notify_resource_cache_on_variable_change.up.sql @@ -0,0 +1,23 @@ +-- Add up migration script here +CREATE OR REPLACE FUNCTION notify_var_resource_cache_change() +RETURNS TRIGGER AS $$ +BEGIN + IF TG_TABLE_NAME = 'variable' THEN + PERFORM pg_notify('var_cache_invalidation', + json_build_object( + 'workspace_id', COALESCE(NEW.workspace_id, OLD.workspace_id), + 'path', COALESCE(NEW.path, OLD.path), + 'operation', TG_OP + )::text + ); + END IF; + PERFORM pg_notify('resource_cache_invalidation', + json_build_object( + 'workspace_id', COALESCE(NEW.workspace_id, OLD.workspace_id), + 'path', COALESCE(NEW.path, OLD.path), + 'operation', TG_OP + )::text + ); + RETURN COALESCE(NEW, OLD); +END; +$$ LANGUAGE plpgsql; \ No newline at end of file