VitorAndrey
VitorAndrey
DTDrizzle Team
Created by VitorAndrey on 2/8/2024 in #help
Migration Error after building with Electron
Ok thank you so much man!
9 replies
DTDrizzle Team
Created by VitorAndrey on 2/8/2024 in #help
Migration Error after building with Electron
I see 👏 ,very clever! now I've to get it done with this electron-vite template I'm testing https://electron-vite.org/guide/. I'm not sure if they use webpack, I will check in docs but you helped a lot, now I lest I know what I need to learn to get it done. 😁 Thnx!
9 replies
DTDrizzle Team
Created by VitorAndrey on 2/8/2024 in #help
Migration Error after building with Electron
Hey man! I was actually trying to solve this right now then I saw your message lol. I've been fighting against this for a while now, and I remembered this morning that I used userData path to create the database file in in the same place it will be after build. Then I'm trying to do the same with migrations folder.
const userDataPath = app.getPath('userData')
const appDataPath = join(userDataPath, 'Database')

if (!fs.existsSync(appDataPath)) {
fs.mkdirSync(appDataPath)
}

const dbPath = join(appDataPath, 'sqlite.db')

export const betterSqlite = new Database(dbPath)
const db = drizzle(betterSqlite, { schema: { ...productSchema } })

migrate(db, { migrationsFolder: 'src/database/migrations' })

export { db }
const userDataPath = app.getPath('userData')
const appDataPath = join(userDataPath, 'Database')

if (!fs.existsSync(appDataPath)) {
fs.mkdirSync(appDataPath)
}

const dbPath = join(appDataPath, 'sqlite.db')

export const betterSqlite = new Database(dbPath)
const db = drizzle(betterSqlite, { schema: { ...productSchema } })

migrate(db, { migrationsFolder: 'src/database/migrations' })

export { db }
Notice that I used this dynamic dbPath variable which uses userDataPath to create the database file in an absolute location that works fine after build as well. I was looking for do the same thing with migrations folder something with same idea as your approach.
9 replies