mirror of
https://github.com/bitbaum/hirnli.git
synced 2026-12-04 12:08:16 +01:00
Every tenant-scoped org_id carried default('revamp-it'), and three ingestion
scripts wrote that literal. With one customer it is invisible; with two, any
write that forgets to say whose data it is files the row under Revamp-IT and
nothing afterwards distinguishes it. The attribution is not wrong in a
recoverable way — it is gone.
'Whose data is this?' has no sensible fallback, so an unanswered question now
stops the write. Removing the Drizzle defaults made TypeScript name five write
paths that had never said whose data they created, including three
activity-log writes that would have logged evig's actions as Revamp-IT's.
Migration 0011 drops the defaults in the database too, so an unattributed
insert is rejected rather than silently attributed (verified against the live
DB: null value in column org_id violates not-null constraint).
The ingestion scripts now take --org / HIRNLI_ORG_ID and refuse to start
without one.
Two further findings while doing it:
config_data never contained orgId on ANY of the 16,623 rows — the Zod
.default('revamp-it') manufactured it on every parse, so every foundation
reported itself as Revamp-IT's regardless of its actual column. The composed
schema then did .omit({ orgId: true }), stripping the invented value right
back out. The codebase already knew the field did not belong; it is gone.
getTenantByHost() and the static TENANTS map are deleted. They were a SECOND
reader of tenant identity built from the compile-time constant, and they
returned undefined for evig — a tenant with a profile, a logo and a
membership but deliberately no hardcoded entry. One reader, reading the
database.
evig also gains a host, having had an identity before it had an address.
Claude-Session: https://claude.ai/code/session_01HVwg8DKHQktxJuHeLM3xpG
Co-authored-by: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
39 lines
1.6 KiB
TypeScript
39 lines
1.6 KiB
TypeScript
/**
|
|
* Which tenant is this script writing for? Answer explicitly or don't run.
|
|
*
|
|
* The ingestion scripts each wrote the literal `'revamp-it'`, and every
|
|
* tenant-scoped column carried `default('revamp-it')` to match. With one
|
|
* customer that is invisible. With two it means a script run for evig files its
|
|
* rows under Revamp-IT, and afterwards nothing distinguishes them — the
|
|
* attribution is not wrong in a recoverable way, it is simply gone.
|
|
*
|
|
* A default is the wrong shape for this. "Whose data is this?" has no sensible
|
|
* fallback, so an unanswered question must stop the run rather than be answered
|
|
* on the operator's behalf.
|
|
*/
|
|
|
|
/**
|
|
* The org id to write, from `--org <id>` or `HIRNLI_ORG_ID`.
|
|
*
|
|
* Throws when absent. That is the feature: a script that cannot say whose data
|
|
* it is producing should not produce any.
|
|
*/
|
|
export function requireOrgId(argv: string[] = process.argv): string {
|
|
const flagIndex = argv.indexOf('--org');
|
|
const fromFlag = flagIndex !== -1 ? argv[flagIndex + 1] : undefined;
|
|
const orgId = (fromFlag ?? process.env.HIRNLI_ORG_ID ?? '').trim();
|
|
|
|
if (!orgId) {
|
|
throw new Error(
|
|
'No organisation given. Pass --org <id> or set HIRNLI_ORG_ID.\n' +
|
|
'There is deliberately no default: an unattributed row is indistinguishable\n' +
|
|
"from the first tenant's, and that cannot be undone after the fact.",
|
|
);
|
|
}
|
|
if (orgId.startsWith('-')) {
|
|
// `--org --dry-run` would otherwise file every row under "--dry-run".
|
|
throw new Error(`"${orgId}" looks like a flag, not an organisation id.`);
|
|
}
|
|
return orgId;
|
|
}
|