Files

27 lines
1.3 KiB
TypeScript

// Read-only: per demo tenant, count Kontakt (total / demo / visible) + InboxLead,
// to confirm whether seeded CRM contacts exist but are hidden by the isDemoData
// default filter. RLS-scoped counts. No writes.
import { getDbClient } from "@hivegrid/db/client.server";
const DEMO_SLUGS = ["demo-starter-crm", "demo-pro-crm", "demo-business-crm"];
const db = getDbClient() as any;
async function rls<T>(tenantId: string, cb: (tx: any) => Promise<T>): Promise<T> {
return db.$transaction(async (tx: any) => {
await tx.$executeRaw`SELECT set_config('app.tenant_id', ${tenantId}, true)`;
return cb(tx);
});
}
const tenants = await db.tenant.findMany({ where: { slug: { in: DEMO_SLUGS } }, select: { id: true, slug: true } });
for (const t of tenants) {
await rls(t.id, async (tx: any) => {
const kTotal = await tx.kontakt.count({ where: { tenantId: t.id } });
const kDemo = await tx.kontakt.count({ where: { tenantId: t.id, isDemoData: true } });
const kVisible = await tx.kontakt.count({ where: { tenantId: t.id, isDemoData: false, archivedAt: null } });
const leads = await tx.inboxLead.count({ where: { tenantId: t.id } });
console.log(`${t.slug}: kontakt total=${kTotal} demo=${kDemo} visible(default)=${kVisible} | inboxLead=${leads}`);
});
}
process.exit(0);