-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdrizzle.config.ts
51 lines (42 loc) · 1.28 KB
/
drizzle.config.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
import path from "path";
import { fileURLToPath } from "url";
import fs from "fs";
import type { Config } from "drizzle-kit";
const getLocalDb = () => {
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const dbPath = path.resolve(__dirname, "./.wrangler/state/v3/d1/miniflare-D1DatabaseObject");
const files = fs.readdirSync(dbPath);
for (const file of files) {
if (file.endsWith(".sqlite")) {
return path.resolve(dbPath, file);
}
}
};
const isDev = process.env.ENV == "dev";
let dbCredentials;
if (isDev) {
dbCredentials = {
url: getLocalDb()
};
} else {
dbCredentials = {
wranglerConfigPath: "wrangler.toml",
dbName: "serverless-docs-db"
};
}
export default {
schema: "src/lib/db/schema.ts",
out: "migrations",
dialect: "sqlite",
driver: "d1-http",
dbCredentials
} satisfies Config;
/**
Create your D1 database via dashboard or with bunx wrangler d1 create my-db-prod.
Copy the console output database_name and database_id.
Go to wrangler.toml and change database_name and database_id.
Go to drizzle.config.ts and change db name in dbName.
Go to package.json and change db name in db:push:* and db:backup:prod.
Generate and migrate the schema to dev or prod db:
bun run db:migrate; bun run db:push:dev; bun run db:push:prod.
*/