-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathdrizzle.config.ts
50 lines (44 loc) · 1.19 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
import 'dotenv/config';
import { defineConfig } from 'drizzle-kit';
import { execSync } from 'child_process';
declare global {
interface Process {
env: {
DATABASE_ID: string;
ACCOUNT_ID: string;
TOKEN: string;
NODE_ENV: string;
}
}
var process: Process;
}
const getSqlitePath = () => {
try {
return execSync('find .wrangler/state/v3/d1/miniflare-D1DatabaseObject -type f -name "*.sqlite" -print -quit', { encoding: 'utf-8' }).trim();
} catch (e) {
console.error('Failed to find SQLite database file');
return '';
}
};
const cloudflareConfig = defineConfig({
out: './drizzle',
schema: './src/db/schema.ts',
dialect: 'sqlite',
driver: "d1-http",
dbCredentials: {
accountId: process.env.ACCOUNT_ID,
databaseId: process.env.DATABASE_ID,
token: process.env.TOKEN,
},
});
const localConfig = defineConfig({
out: './drizzle',
schema: './src/db/schema.ts',
dialect: 'sqlite',
dbCredentials: {
url: `file:${getSqlitePath()}`,
},
});
const config = process.env.NODE_ENV === "production" ? cloudflareConfig : localConfig;
console.log(`Using ${process.env.NODE_ENV === "production" ? "cloudflare" : "local"} config`);
export default config;