mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 12:25:22 +00:00
* wip on refactoring docs * wip * initial structured logs impl * structured log docs * create logger package * add news entry for structured logging * add logger package to dockerfile and cleanup * add gh workflow for catching broken links * further wip * fix * further wip on docs * review feedback * remove logger dep from mcp package * fix build errors * add back auth_url warning * fix sidebar title consistency --------- Co-authored-by: bkellam <bshizzle1234@gmail.com>
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { PrismaClient } from "@sourcebot/db";
|
|
import { ArgumentParser } from "argparse";
|
|
import { migrateDuplicateConnections } from "./scripts/migrate-duplicate-connections";
|
|
import { confirmAction } from "./utils";
|
|
import { createLogger } from "@sourcebot/logger";
|
|
|
|
export interface Script {
|
|
run: (prisma: PrismaClient) => Promise<void>;
|
|
}
|
|
|
|
export const scripts: Record<string, Script> = {
|
|
"migrate-duplicate-connections": migrateDuplicateConnections,
|
|
}
|
|
|
|
const parser = new ArgumentParser();
|
|
parser.add_argument("--url", { required: true, help: "Database URL" });
|
|
parser.add_argument("--script", { required: true, help: "Script to run" });
|
|
const args = parser.parse_args();
|
|
|
|
const logger = createLogger('db-script-runner');
|
|
|
|
(async () => {
|
|
if (!(args.script in scripts)) {
|
|
logger.error("Invalid script");
|
|
process.exit(1);
|
|
}
|
|
|
|
const selectedScript = scripts[args.script];
|
|
|
|
logger.info("\nTo confirm:");
|
|
logger.info(`- Database URL: ${args.url}`);
|
|
logger.info(`- Script: ${args.script}`);
|
|
|
|
confirmAction();
|
|
|
|
const prisma = new PrismaClient({
|
|
datasourceUrl: args.url,
|
|
});
|
|
|
|
await selectedScript.run(prisma);
|
|
|
|
logger.info("\nDone.");
|
|
process.exit(0);
|
|
})();
|
|
|