Skip to content

Latest commit

 

History

History
122 lines (87 loc) · 2.39 KB

File metadata and controls

122 lines (87 loc) · 2.39 KB
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]
  }
}

🔗 Related Resources