Quick start with SQLite
Use a new SQLite project to create, apply and roll back one SQL migration.
Install
sh
go install github.com/exc-works/migrate/cmd/migrate@latest
migrate --help
migrate versionSee Installation for source installation and PATH setup, or database capabilities for supported migration formats.
Configure
sh
mkdir migrate-demo
cd migrate-demo
migrate new configReplace the generated migration_config.yml with:
yaml
# Table that records migration history
schema_name: migration_schema
dialect: sqlite
data_source_name: ./demo.sqlite # Local SQLite file
working_directory: .
migrate_out_of_order: false
logger_level: info
migration_source: migrations # Migration directoryCreate a migration
sh
migrate create
migrate new version "init users" -v 202611030001Replace migrations/V202611030001__init_users.sql with:
sql
-- +migrate Up
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL
);
-- +migrate Down
DROP TABLE users;Apply and verify
sh
migrate up --dry-run
migrate up
migrate statusConfirm version 202611030001 is applied.
Roll back
sh
migrate down --all --dry-run
migrate down --all
migrate statusConfirm the table is removed and the version is pending.
Continue with writing SQL migrations, configuration or JavaScript and TypeScript migrations.