A utility for database migrations with sqlite3.
The module using user_version to record the schema version.
interface IMigration {
version: number
up: string | ((db: Database) => void)
down: string | ((db: Database) => void)
}You may need migration-files.
function migrate(db: Database, migrations: IMigration[], targetVersion?: number): voidIf targetVersion is undefined, then use the maximum version of migrations.
Yes, the user_version update is visible to every database connection.
When the maximum migration version is less than the user_version (which means it is an obsolete instance), it will skip the migration.
You may need a proper retry strategy,
because each migration uses BEGIN IMMEDIATE to ensure that parallel write transactions fail early.