name: db-migrate description: Database migration management - Use Flyway and Atlas for version-controlled database schema migrations
Database Migration Skill
๐ Overview
Provides two modern database migration tools:
- Flyway: Mature and stable, based on versioned SQL scripts
- Atlas: Modern, declarative schema management
๐ง Prerequisites
Flyway
| Tool | Installation |
|---|---|
| Java 11+ | adoptium.net |
| Flyway CLI | Download |
Atlas
| Tool | Windows | Linux/Mac |
|---|---|---|
| Atlas | scoop install atlas |
brew install ariga/tap/atlas |
๐ Usage
Flyway Migration
Create migration script:
.\.agent\skills\db-migrate\scripts\flyway-create.ps1 -Name "add_users_table"
# Generates: V1__add_users_table.sql
Execute migration:
.\.agent\skills\db-migrate\scripts\flyway-migrate.ps1
Rollback migration:
.\.agent\skills\db-migrate\scripts\flyway-undo.ps1
Atlas Migration
Schema diff:
.\.agent\skills\db-migrate\scripts\atlas-diff.ps1
Auto-generate migration:
.\.agent\skills\db-migrate\scripts\atlas-migrate.ps1 -Auto
๐ฏ Features
Flyway
- โ Versioned SQL migrations (V1__xxx.sql)
- โ Repeatable migrations (R__xxx.sql)
- โ Rollback support
- โ Migration history tracking
Atlas
- โ Declarative schema definition (HCL)
- โ Auto-generated migration scripts
- โ Visual schema diff
- โ Linting and validation
๐ Migration Script Examples
Flyway (V1__create_users.sql):
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
email VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
CREATE INDEX idx_users_email ON users(email);
Atlas (schema.hcl):
table "users" {
schema = schema.public
column "id" {
type = serial
}
column "username" {
type = varchar(50)
null = false
}
primary_key {
columns = [column.id]
}
index "idx_users_email" {
columns = [column.email]
}
}