https://github.com/blackglory/deno-sqlite-migrations
🌿
https://github.com/blackglory/deno-sqlite-migrations
deno jsr-package library typescript
Last synced: 2 days ago
JSON representation
🌿
- Host: GitHub
- URL: https://github.com/blackglory/deno-sqlite-migrations
- Owner: BlackGlory
- License: mit
- Created: 2025-08-12T12:40:46.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2026-02-11T05:55:12.000Z (4 months ago)
- Last Synced: 2026-02-11T12:32:15.556Z (4 months ago)
- Topics: deno, jsr-package, library, typescript
- Language: TypeScript
- Homepage: https://jsr.io/@blackglory/sqlite-migrations
- Size: 19.5 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# deno-sqlite-migrations
A utility for database migrations with [sqlite3].
The module using [user_version] to record the schema version.
[sqlite3]: https://github.com/denodrivers/sqlite3
[user_version]: https://www.sqlite.org/pragma.html#pragma_user_version
## Install
```sh
deno add jsr:@blackglory/sqlite-migrations
```
## API
```ts
interface IMigration {
// An integer starting from 1
version: number
up: string | ((db: Database) => void)
down: string | ((db: Database) => void)
}
```
You may need [migration-files].
[migration-files]: https://github.com/BlackGlory/migration-files
### migrate
```ts
function migrate(
db: Database
, migrations: IMigration[]
, options?: {
targetVersion?: number
throwOnNewerVersion?: boolean = false
}
): void
```
If `options.targetVersion` is `undefined`,
the maximum version of the `migrations` is used.
When the maximum known migration version is less than the `user_version`,
it means the current instance is outdated.
- When `options.throwOnNewerVersion` is `false` (default),
it will skip the migration,
so your outdated instance continues to run.
- When `options.throwOnNewerVersion` is `true`,
it will throw an error,
so your outdated instance fails immediately.
#### Can multiple instances migrate in parallel?
Yes, the `user_version` update is visible to every database connection.
Each migration uses `BEGIN IMMEDIATE` to ensure that parallel write transactions fail early.
Therefore, you may need a proper retry strategy.