apps/product-analytics: a standalone Node 22 service (hono, pg, fflate, jose)
that speaks the public SDK capture protocol (/e/, /i/v0/e/, /batch/,
/capture/, /engage/, /groups/, /flags/?v=2, /decide/, /array/:token/config)
over JSON, gzip, base64 and form data, stores into Postgres (monthly
partitions, RLS on pa.project_id plus a bound project_id), resolves people
with identify/alias/merge semantics ported from the upstream persons code
(MIT, cbb1e9253027), applies the console caps (byte copy, drift-tested),
meters scribase.analytics.events behind RAILYARD_LIVE, drops IPs, runs
privacy deletions as visible jobs and trims to each plan's window.
Hand-offs created now (empty on purpose):
- src/routes.ts mounts src/insights/routes.ts -> A2
- src/routes.ts mounts src/{replay,heatmaps,surveys,experiments,exports}/routes.ts -> A3
- src/remote-config/sections.ts (replay, heatmaps, surveys providers) -> A3
- src/flags/variants.ts (returns null) -> A3
- src/replay/gdpr.ts and src/surveys/gdpr.ts privacy hooks -> A3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
1.0 KiB
TypeScript
28 lines
1.0 KiB
TypeScript
// Applies db/migrations/*.sql in order (each file is idempotent). Run by the database owner:
|
|
// DATABASE_URL=... node scripts/migrate.ts
|
|
import { readdirSync, readFileSync } from "node:fs";
|
|
import { dirname, join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import pg from "pg";
|
|
|
|
const DIR = join(dirname(fileURLToPath(import.meta.url)), "..", "db", "migrations");
|
|
export const MIGRATIONS = readdirSync(DIR).filter((f) => /^\d{4}_.*\.sql$/.test(f)).sort();
|
|
|
|
export async function migrate(url: string): Promise<string[]> {
|
|
const client = new pg.Client({ connectionString: url });
|
|
await client.connect();
|
|
try {
|
|
for (const f of MIGRATIONS) await client.query(readFileSync(join(DIR, f), "utf8"));
|
|
return MIGRATIONS;
|
|
} finally {
|
|
await client.end();
|
|
}
|
|
}
|
|
|
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
const url = process.env.DATABASE_URL;
|
|
if (!url) throw new Error("DATABASE_URL is required");
|
|
const done = await migrate(url);
|
|
console.log(`applied ${done.length} migrations`);
|
|
}
|