I am using sqlite as my database for an offline app which is made in electron. For creating the database, I was using knex migrations. Problem is, it will run fine in development, i would migrate the database and start the electron process.
But while packaging the app for production build, I need the migrations to run on the client machine on the first start up. So that the database would be created and when there is an application update, a new migration would keep the database updated.
What is the appropriate approach for this. How do i run the migrations on app start up, or how do i keep the migrations in the bundle. Won't all the code be kept in app.asar? Will the migration code be run from there?
Also, where should the database be created in the client machine?
If you are using electron builder then you can add this to the electron-builder.json
"extraFiles": "migrations/*",
where migrations is the folder where you keep the migrations.
To migrate it automatically on running
you can add the following code
const client = knex(config[env]);
client.migrate.latest(config);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With