A simple SQLite file-based migration system for Bun.
bun i redraskal/bun-migrate#main
Choose a folder name, or use a default "migrations" folder in your project.
Create a file in your migrations folder with the following name:
1.{name}.sql # Example: 1.initial.sql
Future migrations should have an incrementing or sequential id sequence.
Example:
- 1.initial.sql
- 2.create_accounts.sql
- 6.banana.sql
import Database from "bun:sqlite";
import { migrate, migrations } from "bun-migrate";
const db = new Database("bun.sqlite");
await migrate(db);
// "🌩️ Running migrations..."
// " ⚡ 1.initial.sql"
// " ⚡ 2.create_accounts.sql"
// ...
// or specify a folder
await migrate(db, {
migrations: "./cool_migrations",
});
const files = await migrations("./cool_migrations");
console.log(files);
/**
* [
* {
* id: 1,
* name: "1.initial.sql",
* content: "CREATE TABLE..."
* },
* ...
* ]
*/
This project was created using bun init
in bun v0.6.15. Bun is a fast all-in-one JavaScript runtime.