-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrizzle.config.ts
More file actions
54 lines (49 loc) · 1.63 KB
/
Copy pathdrizzle.config.ts
File metadata and controls
54 lines (49 loc) · 1.63 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { mkdirSync } from "fs";
import { defineConfig } from "drizzle-kit";
// Get database type from environment or default to sqlite
const databaseType = process.env.DATABASE_TYPE || "sqlite";
// Base configuration
const baseConfig = {
schema: "./src/database/schemas/*.mts",
verbose: true,
strict: true,
};
// Resolve the SQLite database URL and ensure its directory exists
// Match the default used by @digital-alchemy/synapse: file:<cwd>/synapse_storage.db
const sqliteUrl = process.env.DATABASE_URL || "file:./synapse_storage.db";
if (databaseType === "sqlite") {
// Strip the "file:" prefix to get the filesystem path, then ensure the directory exists
const filePath = sqliteUrl.replace(/^file:/, "");
const lastSlash = filePath.lastIndexOf("/");
const dirPath = lastSlash > 0 ? filePath.slice(0, lastSlash) : ".";
mkdirSync(dirPath, { recursive: true });
}
// Database-specific configurations
const configs = {
sqlite: {
...baseConfig,
dialect: "sqlite" as const,
out: "./migrations/sqlite",
dbCredentials: {
url: sqliteUrl,
},
},
postgresql: {
...baseConfig,
dialect: "postgresql" as const,
out: "./migrations/postgresql",
dbCredentials: {
url: process.env.DATABASE_URL || "postgresql://localhost:5432/synapse",
},
},
mysql: {
...baseConfig,
dialect: "mysql" as const,
out: "./migrations/mysql",
dbCredentials: {
url: process.env.DATABASE_URL || "mysql://localhost:3306/synapse",
},
},
};
// Export the appropriate configuration based on DATABASE_TYPE
export default defineConfig(configs[databaseType as keyof typeof configs] || configs.sqlite);