Skip to content

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

DatabaseSync

An open database, outside any transaction.

readonly DatabaseMigration[]

Every migration since the empty schema, in order.

number

The version the database was at before.

const database = new DatabaseSync(":memory:");
migrateDatabase(database, ["CREATE TABLE notes (text TEXT) STRICT"]); // 0

When the database is past the last migration, written by a newer application; it is left untouched.

The error of a failing migration, after rolling it back.