-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrizzle.dev.config.ts
More file actions
33 lines (29 loc) · 1.05 KB
/
drizzle.dev.config.ts
File metadata and controls
33 lines (29 loc) · 1.05 KB
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
import "dotenv/config";
import { defineConfig } from "drizzle-kit";
import path from "node:path";
import fs from "node:fs";
// Oddly enough, you will get:
// Reading config file '.../HopeFlow/webapp/drizzle.dev.config.ts'
// require is not defined in ES module scope, you can use import instead
// error if you using following three lines to get current script path
// import { fileURLToPath } from "node:url";
// const __filename = fileURLToPath(import.meta.url);
// const __dirname = __filename.replace(/\/[^/]+$/, "");
const d1DatabaseObjectPath = path.join(
__dirname,
".wrangler/state/v3/d1/miniflare-D1DatabaseObject",
);
const sqliteFilePath = fs
.readdirSync(d1DatabaseObjectPath)
.find((f) => f.endsWith(".sqlite"));
if (!sqliteFilePath) {
throw new Error(
`No SQLite file found in ${d1DatabaseObjectPath}. Please ensure the D1 database is set up correctly.`,
);
}
export default defineConfig({
out: "./drizzle",
schema: "./src/db/schema.ts",
dialect: "sqlite",
dbCredentials: { url: path.join(d1DatabaseObjectPath, sqliteFilePath) },
});