@@ -3,61 +3,43 @@ import fs from 'fs';
33import path from 'path' ;
44
55interface DbSelection {
6- type : 'sqlite' | 'postgres' ;
7- dbPath ?: string ; // For sqlite
8- connectionString ?: string ; // For postgres
6+ type : 'sqlite' ;
7+ dbPath : string ;
98}
109
1110// Function to read config (simplified, synchronous for CLI tool)
1211function getDbSelectionConfig ( ) : DbSelection | null {
13- // Assumes drizzle.config.ts is in services/backend/
14- const configPath = path . resolve ( __dirname , './data /db.selection.json' ) ;
12+ // Updated path to match the actual location used by the application
13+ const configPath = path . resolve ( __dirname , './persistent_data /db.selection.json' ) ;
1514 try {
1615 if ( fs . existsSync ( configPath ) ) {
1716 const raw = fs . readFileSync ( configPath , 'utf-8' ) ;
1817 return JSON . parse ( raw ) as DbSelection ;
1918 }
20- console . log ( "db.selection.json not found, defaulting to SQLite for drizzle-kit." ) ;
19+ console . log ( "db.selection.json not found, using default SQLite configuration for drizzle-kit." ) ;
2120 } catch ( e ) {
22- console . error ( "Error reading db.selection.json for drizzle-kit, defaulting to SQLite:" , e ) ;
21+ console . error ( "Error reading db.selection.json for drizzle-kit, using default SQLite configuration :" , e ) ;
2322 }
2423 return null ; // Default to SQLite if no config or error
2524}
2625
2726const dbSelection = getDbSelectionConfig ( ) ;
2827
29- let drizzleKitConfig : Config ;
28+ // Default SQLite configuration
29+ const sqliteDbPath = ( dbSelection ?. dbPath )
30+ ? dbSelection . dbPath
31+ : 'persistent_data/database/deploystack.db' ; // Default SQLite path
3032
31- if ( dbSelection && dbSelection . type === 'postgres' && dbSelection . connectionString ) {
32- console . log ( "[INFO] drizzle.config.ts: Using PostgreSQL dialect for drizzle-kit." ) ;
33- drizzleKitConfig = {
34- dialect : "postgresql" ,
35- schema : "./src/db/schema.pg.ts" , // Point to PG-specific schema for drizzle-kit
36- out : "./drizzle/migrations_pg" , // PostgreSQL specific migrations
37- dbCredentials : {
38- url : dbSelection . connectionString , // drizzle-kit uses 'url' for PG connection string
39- } ,
40- } ;
41- } else {
42- // Default to SQLite if no config, error, or SQLite selected
43- const sqliteDbPath = ( dbSelection ?. type === 'sqlite' && dbSelection . dbPath )
44- ? dbSelection . dbPath
45- : './data/deploystack.db' ; // Default SQLite path
33+ console . log ( `[INFO] drizzle.config.ts: Using SQLite dialect for drizzle-kit. DB path: ${ sqliteDbPath } ` ) ;
4634
47- // Ensure the path used by drizzle-kit for SQLite is relative to `services/backend`
48- // If dbPath from config is like "data/deploystack.db", it's already correct.
49- // If it's absolute, drizzle-kit might handle it, but relative is safer.
50- // For SQLite, `url` should be the file path.
51- console . log ( `[INFO] drizzle.config.ts: Using SQLite dialect for drizzle-kit. DB path: ${ sqliteDbPath } ` ) ;
52- drizzleKitConfig = {
53- dialect : "sqlite" ,
54- schema : "./src/db/schema.sqlite.ts" , // Point to SQLite-specific schema for drizzle-kit
55- out : "./drizzle/migrations_sqlite" , // SQLite specific migrations
56- dbCredentials : {
57- url : path . isAbsolute ( sqliteDbPath ) ? sqliteDbPath : path . resolve ( __dirname , sqliteDbPath ) ,
58- } ,
59- } ;
60- }
35+ const drizzleKitConfig : Config = {
36+ dialect : "sqlite" ,
37+ schema : "./src/db/schema.sqlite.ts" , // Point to SQLite-specific schema for drizzle-kit
38+ out : "./drizzle/migrations_sqlite" , // SQLite specific migrations
39+ dbCredentials : {
40+ url : path . isAbsolute ( sqliteDbPath ) ? sqliteDbPath : path . resolve ( __dirname , sqliteDbPath ) ,
41+ } ,
42+ } ;
6143
6244export default defineConfig ( {
6345 ...drizzleKitConfig ,
0 commit comments