@launchql/migrate
v2.4.0
Published
LaunchQL Migrate
Readme
@launchql/migrate
A TypeScript-based database migration system for PostgreSQL that replaces Sqitch with a native implementation.
Features
- Native TypeScript: No external dependencies on Sqitch
- PostgreSQL-based state tracking: All migration state is stored in the database
- Dependency management: Supports change dependencies
- Verification support: Built-in support for verify scripts
- Import from Sqitch: Can import existing Sqitch deployments
- Drop-in replacement: Compatible with existing Sqitch plan files
Installation
npm install @launchql/migrateUsage
As a Library
import { LaunchQLMigrate } from '@launchql/migrate';
const migrate = new LaunchQLMigrate({
host: 'localhost',
port: 5432,
user: 'postgres',
password: 'password',
database: 'postgres'
});
// Deploy changes
const deployResult = await migrate.deploy({
project: 'myproject',
targetDatabase: 'myapp',
planPath: './launchql.plan'
});
// Revert changes
const revertResult = await migrate.revert({
project: 'myproject',
targetDatabase: 'myapp',
planPath: './launchql.plan'
});
// Verify deployment
const verifyResult = await migrate.verify({
project: 'myproject',
targetDatabase: 'myapp',
planPath: './launchql.plan'
});
// Check status
const status = await migrate.status('myproject');
// Import from existing Sqitch deployment
await migrate.importFromSqitch();
// Don't forget to close the connection
await migrate.close();As a Drop-in Replacement for Sqitch
import { deployCommand, revertCommand, verifyCommand } from '@launchql/migrate';
const config = {
host: 'localhost',
port: 5432,
user: 'postgres',
password: 'password'
};
// Replace spawn('sqitch', ['deploy', 'db:pg:mydb'])
await deployCommand(config, 'mydb', '/path/to/project');
// Replace spawn('sqitch', ['revert', 'db:pg:mydb'])
await revertCommand(config, 'mydb', '/path/to/project');
// Replace spawn('sqitch', ['verify', 'db:pg:mydb'])
await verifyCommand(config, 'mydb', '/path/to/project');Migration Schema
The migration system creates a launchql_migrate schema in your PostgreSQL database with the following tables:
projects: Tracks migration projectschanges: Records deployed changes with their script hashesdependencies: Tracks change dependenciesevents: Logs deployment events (deploy, revert, fail)
Plan File Format
The system is compatible with Sqitch plan files:
%syntax-version=1.0.0
%project=myproject
%uri=https://github.com/myorg/myproject
schema 2024-01-01T00:00:00Z developer <[email protected]> # Create schema
users [schema] 2024-01-02T00:00:00Z developer <[email protected]> # Create users table
posts [users] 2024-01-03T00:00:00Z developer <[email protected]> # Create posts tableDifferences from Sqitch
- State Storage: Migration state is stored in PostgreSQL instead of a separate registry
- No Tags: The system doesn't support Sqitch tags (yet)
- Simplified Events: Event logging is minimal compared to Sqitch
- Script Hashing: Uses SHA256 for script content hashing
- Native TypeScript: No need to install Sqitch or Perl
License
See LICENSE in the root of the repository.
