migrateDatabase
migrateDatabase(
database,migrations):number
Defined in: packages/node/src/sqlite/migrate-database.ts:51
Brings a SQLite database’s schema up to date, its version kept in PRAGMA user_version: migration n, counted from 0, takes the schema from version
n to n + 1. Each pending migration runs in its own transaction together
with the version update, so a failure leaves the database at the last version
reached.
Migrations are append-only: once released, one is never edited or removed, since databases already past it never run it again.
Time complexity: the migrations applied. Memory: O(1).
Parameters
Section titled “Parameters”database
Section titled “database”DatabaseSync
An open database, outside any transaction.
migrations
Section titled “migrations”readonly DatabaseMigration[]
Every migration since the empty schema, in order.
Returns
Section titled “Returns”number
The version the database was at before.
Example
Section titled “Example”const database = new DatabaseSync(":memory:"); migrateDatabase(database, ["CREATE TABLE notes (text TEXT) STRICT"]); // 0Throws
Section titled “Throws”When the database is past the last migration, written by a newer application; it is left untouched.
Throws
Section titled “Throws”The error of a failing migration, after rolling it back.