Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knex migrations with Electron and sqlite?

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?

like image 363
Pratish Shrestha Avatar asked Mar 13 '18 14:03

Pratish Shrestha


1 Answers

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);

like image 161
Ankur Sheel Avatar answered Oct 11 '22 22:10

Ankur Sheel