Skip to content

Commit

Permalink
Add default DATABASE_URL to db:seed script
Browse files Browse the repository at this point in the history
  • Loading branch information
flenter committed Jun 6, 2024
1 parent d2e4e9b commit 2297f93
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions api/scripts/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import { drizzle } from "drizzle-orm/libsql";
import { githubIssues, mizuLogs } from "../src/db/schema";
config({ path: ".dev.vars" });

const dbUrl = process.env.DATABASE_URL;
import { DEFAULT_DATABASE_URL } from "../src/constants.js";

if (!dbUrl) {
// Set the environment vars
config({ path: ".dev.vars" });
const databaseUrl = process.env.DATABASE_URL ?? DEFAULT_DATABASE_URL;

if (!databaseUrl) {
console.error("DATABASE_URL not defined");
process.exit(1);
}

const db = drizzle(createClient({ url: dbUrl }));
const db = drizzle(createClient({ url: databaseUrl }));

(async () => {
const issuesFile = await fs.readFile(
Expand All @@ -26,6 +30,8 @@ const db = drizzle(createClient({ url: dbUrl }));
const issues = JSON.parse(issuesFile);
const logs = JSON.parse(logsFile);

await db.insert(githubIssues).values(issues);
await db.insert(mizuLogs).values(logs);
let {rowsAffected} = await db.insert(githubIssues).values(issues);
console.log('Inserted', rowsAffected, 'github issues');
({ rowsAffected} = await db.insert(mizuLogs).values(logs));
console.log('Inserted', rowsAffected, 'logs');
})();

0 comments on commit 2297f93

Please sign in to comment.