Multi-tenant platform (182 pages, 228 API routes, ~30 modules) built on a deterministic verification core: clinical-trial claims checked against ClinicalTrials.gov registered results and raw event counts (ARR/NNT/RR+CI recomputed in code, oracle-tested), code-enforced exact-span grounding, and multi-source cross-verification. Auth/RBAC/multi-tenancy, document processing at scale (unpdf + Docling), agentic workflows, Claude Science connector, compliance/audit, billing, public API, and more. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import "dotenv/config";
|
|
import { readFileSync, existsSync, readdirSync } from "fs";
|
|
import { join } from "path";
|
|
import { Pool } from "pg";
|
|
|
|
// Applies the base db/migrations.sql first, then every db/migrations/*.sql in
|
|
// filename order. All migration files are expected to be idempotent, so this is
|
|
// safe to run repeatedly.
|
|
async function main() {
|
|
const connectionString = process.env.DATABASE_URL;
|
|
if (!connectionString) {
|
|
console.error("DATABASE_URL is not set. Copy .env.example to .env.local and fill it in.");
|
|
process.exit(1);
|
|
}
|
|
const pool = new Pool({ connectionString, ssl: { rejectUnauthorized: false } });
|
|
|
|
const dbDir = join(__dirname, "..", "db");
|
|
const baseSqlPath = join(dbDir, "migrations.sql");
|
|
if (existsSync(baseSqlPath)) {
|
|
console.log("Applying db/migrations.sql ...");
|
|
await pool.query(readFileSync(baseSqlPath, "utf-8"));
|
|
}
|
|
|
|
const migrationsDir = join(dbDir, "migrations");
|
|
if (existsSync(migrationsDir)) {
|
|
const files = readdirSync(migrationsDir)
|
|
.filter((f) => f.endsWith(".sql"))
|
|
.sort();
|
|
for (const file of files) {
|
|
console.log(`Applying db/migrations/${file} ...`);
|
|
await pool.query(readFileSync(join(migrationsDir, file), "utf-8"));
|
|
}
|
|
}
|
|
|
|
console.log("Migration complete.");
|
|
await pool.end();
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error("Migration failed:", err);
|
|
process.exit(1);
|
|
});
|