A modern, fast database migration library built for Bun.
- 🚀 Fast: Built with Bun for maximum performance
- 🔒 Type-safe: Full TypeScript support with strict type checking
- 🗄️ Database agnostic: Support for multiple database engines
- 📝 Migration tracking: Automatic migration state management
- 🔄 Rollback support: Easy rollback to previous versions
- 🧪 Testing friendly: Built-in testing utilities
bun add latterimport { Latter, Migration } from 'latter';
// Create a migration
const migration = new Migration({
name: 'create_users_table',
up: `
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
`,
down: 'DROP TABLE users;'
});
// Initialize and run migrations
const latter = new Latter({
database: 'sqlite:./app.db', // or 'postgresql://user:pass@localhost/db' or 'mysql://user:pass@localhost/db'
migrationsDir: './migrations'
});
await latter.migrate();Latter supports multiple database engines out of the box:
const latter = new Latter({
database: 'sqlite:./app.db',
migrationsDir: './migrations'
});const latter = new Latter({
database: 'postgresql://username:password@localhost:5432/database',
migrationsDir: './migrations'
});const latter = new Latter({
database: 'mysql://username:password@localhost:3306/database',
migrationsDir: './migrations'
});class Migration {
constructor(options: {
name: string;
up: string;
down: string;
dependencies?: string[];
});
}class Latter {
constructor(options: {
database: string;
migrationsDir: string;
tableName?: string;
});
async migrate(): Promise<void>;
async rollback(steps?: number): Promise<void>;
async status(): Promise<MigrationStatus[]>;
}Latter comes with a powerful command-line interface for managing migrations:
# Show help
latter --help
# Initialize a new migration project
latter init --migrations-dir ./migrations
latter init --database sqlite:./app.db --migrations-dir ./migrations
# Run pending migrations
latter migrate --database sqlite:./app.db --migrations-dir ./migrations
# Show migration status
latter status --database sqlite:./app.db --migrations-dir ./migrations
# Rollback the last N migrations
latter rollback 2 --database sqlite:./app.db --migrations-dir ./migrations
# Create a new migration
latter create add_users_table --migrations-dir ./migrations
# Use custom table name
latter migrate --database sqlite:./app.db --migrations-dir ./migrations --table-name custom_migrations
# Enable verbose output
latter migrate --database sqlite:./app.db --migrations-dir ./migrations --verbose
# Dry run (show what would be done)
latter migrate --database sqlite:./app.db --migrations-dir ./migrations --dry-run# Run all tests
bun test
# Run specific test files
bun test src/test/adapters.test.ts
bun test src/test/cli.test.ts# Build the project
bun run build
# Build and watch for changes
bun run build:watchThis project uses GitHub Actions for continuous integration:
- Tests: Runs on every push and pull request across multiple Node.js and Bun versions
- Cross-platform: Tests on Ubuntu, Windows, and macOS with proper shell handling
- Quick feedback: Fast test runs for immediate feedback
- Comprehensive coverage: Matrix testing for thorough validation
- Platform-specific commands: Uses appropriate shells (bash for Unix, PowerShell for Windows)
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
MIT