#370 — Facade remove outdated notifications

Repo: Twill-AI/facade State: open | Status: open Assignee: Unassigned

Created: 2025-06-17 · Updated: 2025-09-15

Description

Request

On some tenants in staging number of notifications is 1954. They are old and useless.

Query to get number of notifications in all tenants
DROP FUNCTION IF EXISTS find_tenants();
CREATE OR REPLACE FUNCTION find_tenants()
RETURNS TABLE (
    schema_name text,
    value text
) AS $$
DECLARE
    query text;
BEGIN
    FOR query IN
        SELECT format(
            'SELECT %L::text as schema_name, count(*)::text as value FROM %I.notification',
            nspname,
            nspname
        )
        FROM pg_catalog.pg_namespace 
        WHERE nspname LIKE 'facade_%'
        AND not nspname in ('facade_master')
    LOOP
        RETURN QUERY EXECUTE query;
    END LOOP;
END;
$$ LANGUAGE plpgsql;
SELECT * FROM find_tenants() ORDER BY schema_name;

Acceptance criteria

  • Logic of removing outdated notifications is discussed and approved with Michael, Nader, Nathan.
  • Facade have mechanism (job?) to remove outdated notifications.
  • Logic above is covered with unit tests.

Notes

Add implementation notes, blockers, and context here

Add wikilinks to related people, meetings, or other tickets