mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
50 lines
2.4 KiB
TypeScript
50 lines
2.4 KiB
TypeScript
import { PostgresRouter, PostgresUse } from '~/common/utils/db/postgres'
|
|
|
|
// Matches "test" only as an underscore- or boundary-delimited token, so real
|
|
// test databases (test_insights, insights_test) pass while names that merely
|
|
// embed the substring (latest, insights_latest) are still refused.
|
|
const TEST_DATABASE_NAME_PATTERN = /(^|_)test(_|$)/i
|
|
|
|
/**
|
|
* Throws unless `databaseName` looks like a test database — i.e. it contains
|
|
* "test" as an underscore- or boundary-delimited token (test_insights,
|
|
* insights_test). Names that merely embed the substring (latest, mytest) are
|
|
* refused.
|
|
*
|
|
* Destructive test helpers (mass DELETE/TRUNCATE) call this before touching a
|
|
* database, so a misconfigured environment (e.g. NODE_ENV/DEBUG or a
|
|
* DATABASE_URL pointing at the dev `insights` database leaking in from a shell
|
|
* or IDE) produces a loud error instead of silently wiping real dev data.
|
|
*/
|
|
export function assertTestDatabaseName(databaseName: string, source: string): void {
|
|
if (TEST_DATABASE_NAME_PATTERN.test(databaseName)) {
|
|
return
|
|
}
|
|
throw new Error(
|
|
`🛑 Refusing to run a destructive test helper against database "${databaseName}" (${source}).\n\n` +
|
|
`The database name does not contain "test" as a standalone segment, so it looks\n` +
|
|
`like a real development or production database. Continuing would have deleted\n` +
|
|
`data from it.\n\n` +
|
|
`The nodejs tests expect dedicated test databases (test_insights, test_persons,\n` +
|
|
`test_behavioral_cohorts on Postgres; insights_test on Datastore). This error\n` +
|
|
`usually means DATABASE_URL, PERSONS_DATABASE_URL, DATASTORE_DATABASE or similar\n` +
|
|
`leaked in from your shell or IDE. Unset them, or create the test databases with\n` +
|
|
`\`pnpm --filter=@hanzo/nodejs setup:test\`.`
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Asserts that the database a router's pool actually connects to for the given
|
|
* use is a test database. Queries `current_database()` so the check reflects
|
|
* ground truth regardless of how the connection URL was assembled.
|
|
*/
|
|
export async function assertRouterTargetsTestDatabase(router: PostgresRouter, use: PostgresUse): Promise<void> {
|
|
const result = await router.query<{ name: string }>(
|
|
use,
|
|
'SELECT current_database() AS name',
|
|
undefined,
|
|
'database-guard'
|
|
)
|
|
assertTestDatabaseName(result.rows[0].name, `Postgres ${PostgresUse[use]}`)
|
|
}
|