forked from fiberplane/create-honc-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.ts
57 lines (51 loc) · 1.32 KB
/
seed.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { neon } from "@neondatabase/serverless";
import { config } from "dotenv";
import { drizzle } from "drizzle-orm/neon-http";
import * as schema from "./src/db/schema";
config({ path: ".dev.vars" });
// biome-ignore lint/style/noNonNullAssertion: error from neon client is helpful enough to fix
const sql = neon(process.env.DATABASE_URL!);
const db = drizzle(sql);
const seedPullRequests = [
{
title: "Add new feature",
description: "This pull request adds a new feature.",
authorId: 1,
},
{
title: "Fix bug",
description: "This pull request fixes a bug.",
authorId: 2,
},
];
const seedReviews = [
{
pullRequestId: 1,
reviewerId: 3,
comments: "Looks good to me.",
status: "approved",
},
{
pullRequestId: 2,
reviewerId: 1,
comments: "Needs some changes.",
status: "changes_requested",
},
];
async function seed() {
await db.insert(schema.pullRequests).values(seedPullRequests);
await db.insert(schema.reviews).values(seedReviews);
}
async function main() {
try {
await seed();
console.log("✅ Database seeded successfully!");
console.log("🪿 Run `npm run fiberplane` to explore data with your api.");
} catch (error) {
console.error("❌ Error during seeding:", error);
process.exit(1);
} finally {
process.exit(0);
}
}
main();