feat: complete NX9-Auth management and integrity hardening

This commit is contained in:
thakares committed 2026-07-24 16:18:48 +05:30
1 parent dc5417334b
commit a969f9c571
59 files changed
+6508 -290

No files matched your search

@@ -0,0 +1,27 @@
-- nx9-auth: Global Slugs Hardening & Parity Alignment (PostgreSQL)
-- Ensures unified global_slugs registry table, indices, and legacy data integrity.
CREATE TABLE IF NOT EXISTS global_slugs (
slug TEXT PRIMARY KEY NOT NULL,
entity_type TEXT NOT NULL,
entity_id TEXT NOT NULL,
tenant_id TEXT NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
created_at TEXT NOT NULL DEFAULT (to_char(clock_timestamp() AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS"Z"'))
);
CREATE INDEX IF NOT EXISTS idx_global_slugs_entity ON global_slugs(entity_type, entity_id);
CREATE INDEX IF NOT EXISTS idx_global_slugs_tenant ON global_slugs(tenant_id);
-- Explicit backfill for tenants that are not yet in global_slugs.
-- Fails immediately if cross-resource slug collision exists.
INSERT INTO global_slugs (slug, entity_type, entity_id, tenant_id)
SELECT slug, 'tenant', id, id
FROM tenants
WHERE slug IS NOT NULL AND slug NOT IN (SELECT slug FROM global_slugs);
-- Explicit backfill for applications that are not yet in global_slugs.
-- Fails immediately if cross-resource slug collision exists.
INSERT INTO global_slugs (slug, entity_type, entity_id, tenant_id)
SELECT slug, 'application', id, tenant_id
FROM applications
WHERE slug IS NOT NULL AND slug NOT IN (SELECT slug FROM global_slugs);