Kacper Hemperek
Kacper Hemperek
DTDrizzle Team
Created by VitorAndrey on 2/8/2024 in #help
Migration Error after building with Electron
You should edit main part of that most likely https://electron-vite.org/guide/#configuring-electron-vite
9 replies
DTDrizzle Team
Created by VitorAndrey on 2/8/2024 in #help
Migration Error after building with Electron
They use vite instead of webpack not sure how to accomplish the same thing there but I bet you should look if you even have migration folder inside dist file and if not adjust vite config to clone. When you have that working my sollution should work just fine
9 replies
DTDrizzle Team
Created by VitorAndrey on 2/8/2024 in #help
Migration Error after building with Electron
Ok so here is what I did 1. Changed place where migrations are stored from earlier
{
from: path.join(webpackPaths.srcMainPath, 'db/drizzle'),
// changed db/drizzle to drizzle to keep the same relative
// path after app is built to only main.js file
to: path.join(webpackPaths.distMainPath, 'drizzle'),
},
{
from: path.join(webpackPaths.srcMainPath, 'db/drizzle'),
// changed db/drizzle to drizzle to keep the same relative
// path after app is built to only main.js file
to: path.join(webpackPaths.distMainPath, 'drizzle'),
},
Now my dist folder looks like this
dist
config (my project specific config files)
drizzle (my folder with migrations)
main.js
preload.js
dist
config (my project specific config files)
drizzle (my folder with migrations)
main.js
preload.js
2. I changed my drizzle.config.ts to be relative to path depending if im in production environment (not sure if that does anything tbh but did it just in case)
const migrationFolder =
process.env.NODE_ENV === 'development'
? 'src/main/db/drizzle'
: 'release/app/dist/main/db/drizzle';

// eslint-disable-next-line import/no-default-export
export default {
schema: './src/main/db/schema.ts',
out: migrationFolder,
} satisfies Config;
const migrationFolder =
process.env.NODE_ENV === 'development'
? 'src/main/db/drizzle'
: 'release/app/dist/main/db/drizzle';

// eslint-disable-next-line import/no-default-export
export default {
schema: './src/main/db/schema.ts',
out: migrationFolder,
} satisfies Config;
3. I modified my database setup function to get path to migration directory using __dirname like this
function getMigrationPath() {
return path.join(__dirname, 'drizzle');
}

export function setupDatabaseDrizzle() {
const migrationsFolder = getMigrationPath();
// this just returns path to db file
const dbPath = getDatabasePath();
// this DatabaseConnection is alias for Database from better-sqlite
const sqlite = DatabaseConnection(dbPath);
const db = drizzle(sqlite);
migrate(db, { migrationsFolder });
return db;
}
function getMigrationPath() {
return path.join(__dirname, 'drizzle');
}

export function setupDatabaseDrizzle() {
const migrationsFolder = getMigrationPath();
// this just returns path to db file
const dbPath = getDatabasePath();
// this DatabaseConnection is alias for Database from better-sqlite
const sqlite = DatabaseConnection(dbPath);
const db = drizzle(sqlite);
migrate(db, { migrationsFolder });
return db;
}
After i created path to migrations folder with __dirname it started working just fine Hope this helps, if you have any other questions let me know
9 replies
DTDrizzle Team
Created by VitorAndrey on 2/8/2024 in #help
Migration Error after building with Electron
Hey, I encountered exactly same problem, I'm building my main process with webpack and added this this webpack config that builds for prod
const webpackConfig = {
// ...rest of webpack config
plugins: [
// ... other plugins
new CopyWebpackPlugin({
patterns: [
// other patherns if needed, in my case i also copy some config files
{
// this is a path to my migrations folder
from: path.join(webpackPaths.srcMainPath, 'db/drizzle'),
to: path.join(webpackPaths.distMainPath, 'db/drizzle'),
},
],
}),
]
}
const webpackConfig = {
// ...rest of webpack config
plugins: [
// ... other plugins
new CopyWebpackPlugin({
patterns: [
// other patherns if needed, in my case i also copy some config files
{
// this is a path to my migrations folder
from: path.join(webpackPaths.srcMainPath, 'db/drizzle'),
to: path.join(webpackPaths.distMainPath, 'db/drizzle'),
},
],
}),
]
}
even when I did that drizzle still can't find migration folder and I think thats because file path that I setup in drizzle.confg.ts is not coresponding with right folder after I build the app any idea what could i change?
9 replies