databasesqlitedatabase-migrationself-hosting

When creating a self-hosted application, how are database migrations done?


The user will have an SQLite database on their file system. Now I update my application code to add another column, or a whole relationship, or relax a constraint. Do I create a migration script that the app executes on startup? Do I add some code that tries to figure it out depending on the database library I use?


Solution

  • Do I add some code that tries to figure it out depending on the database library I use?

    Probably not e.g. if dropping a constraint the only way it could automatically determine the constraint to be dropped is by comparing the old and new schema by opening both databases and executing statements to check.

    Do I create a migration script that the app executes on startup?

    Probably yes.