forked from wangziqi/gongxue-base
33 lines
1.5 KiB
JavaScript
33 lines
1.5 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
|
|
const migration = fs.readFileSync(
|
|
'supabase/migrations/202607120014_audit_log_capacity_indexes.sql',
|
|
'utf8',
|
|
);
|
|
const tenantRoutes = fs.readFileSync('apps/api/src/features/tenant-admin/routes.ts', 'utf8');
|
|
const platformRoutes = fs.readFileSync('apps/api/src/features/platform-admin/routes.ts', 'utf8');
|
|
const alertWorker = fs.readFileSync('apps/worker/src/jobs/platform-audit-alerts.ts', 'utf8');
|
|
|
|
for (const indexName of [
|
|
'idx_audit_logs_created',
|
|
'idx_audit_logs_tenant_created',
|
|
'idx_audit_logs_tenant_actor_created',
|
|
'idx_audit_logs_tenant_target_created',
|
|
'idx_audit_logs_platform_created',
|
|
]) {
|
|
assert.match(migration, new RegExp(`create index if not exists ${indexName}\\b`, 'i'));
|
|
}
|
|
|
|
assert.match(migration, /\(tenant_id, created_at desc, id desc\)/i);
|
|
assert.match(migration, /\(tenant_id, actor_user_id, created_at desc, id desc\)/i);
|
|
assert.match(migration, /\(tenant_id, target_type, created_at desc, id desc\)/i);
|
|
assert.match(migration, /where action like 'platform\.%'/i);
|
|
|
|
assert.match(tenantRoutes, /const filters = \['al\.tenant_id = \$1'\]/i);
|
|
assert.match(tenantRoutes, /from public\.audit_logs al[\s\S]+order by al\.created_at desc/i);
|
|
assert.match(platformRoutes, /from public\.audit_logs al[\s\S]+order by al\.created_at desc/i);
|
|
assert.match(alertWorker, /from public\.audit_logs al[\s\S]+al\.action like 'platform\.%'[\s\S]+al\.created_at >=/i);
|
|
|
|
console.log('[PASS] audit log capacity index contract');
|