CREATE TABLE IF NOT EXISTS fabric_service_channel_rebuild_alert_silences (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    cluster_id UUID NOT NULL REFERENCES clusters(id) ON DELETE CASCADE,
    reporter_node_id UUID NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,
    route_id TEXT NOT NULL,
    guard_status TEXT NOT NULL,
    generation TEXT NOT NULL DEFAULT '',
    reason TEXT NOT NULL DEFAULT '',
    created_by_user_id UUID REFERENCES users(id) ON DELETE SET NULL,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    expires_at TIMESTAMPTZ NOT NULL,
    payload JSONB NOT NULL DEFAULT '{}'::jsonb,
    UNIQUE (cluster_id, reporter_node_id, route_id, guard_status, generation)
);

CREATE INDEX IF NOT EXISTS idx_fsc_rebuild_alert_silences_active
    ON fabric_service_channel_rebuild_alert_silences (cluster_id, expires_at DESC);
