@blackglory/sqlite3-migrations
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

sqlite3-migrations

A utility for database migrations with sqlite3.

The module using user_version to record the schema version.

Install

npm install --save @blackglory/sqlite3-migrations
# or
yarn add @blackglory/sqlite3-migrations

API

interface IMigration {
  version: number
  up: string | ((db: Database) => PromiseLike<void>)
  down: string | ((db: Database) => PromiseLike<void>)
}

You may need migration-files.

migrate

function migrate(db: Database, migrations: IMigration[], targetVersion?: number): void

If targetVersion is undefined, then use the maximum version of migrations.

FAQ

Can multiple instances migrate in parallel?

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.

Package Sidebar

Install

npm i @blackglory/sqlite3-migrations

Weekly Downloads

2

Version

0.1.0

License

MIT

Unpacked Size

13.8 kB

Total Files

11

Last publish

Collaborators

  • black_glory