migrations
БесплатноБез исполняемых скриптовНе проверенDatabase migration strategies and best practices. Covers schema versioning, zero-downtime migrations, rollback patterns, and data migration techniques. Use…
от claude-dev-suite★ 51 звезда на GitHubОб этом скилле
Database Migrations Core Knowledge
Deep Knowledge: Use
mcp__documentation__fetch_docswith technology:migrationsfor comprehensive documentation.
Migration Fundamentals
What is a Migration?
A migration is a version-controlled change to your database schema or data.
Migration Types
| Type | Description | Example |
|---|---|---|
| Schema | DDL changes | Add column, create index |
| Data | DML changes | Backfill data, transform values |
| Combined | Both schema and data | Add column with default, populate |
Version Naming Conventions
Timestamp-based (Recommended)
V20240115103000__create_users_table.sql
V20240115104500__add_email_index.sql
V20240116090000__add_status_column.sql
Sequential
V001__create_users_table.sql
V002__add_email_index.sql
V003__add_status_column.sql
Semantic
V1.0.0__initial_schema.sql
V1.1.0__add_orders_table.sql
V1.1.1__fix_orders_constraint.sql
Migration File Structure
Flyway Format
-- V20240115103000__create_users_table.sql
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) NOT NULL UNIQUE,
name VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_users_email ON users(email);
With Rollback (Flyway Pro/Enterprise)
-- V20240115103000__create_users_table.sql
CREATE TABLE users (...);
-- U20240115103000__create_users_table.sql (undo)
DROP TABLE IF EXISTS users;
Liquibase Format
<!-- changelog.xml -->
<databaseChangeLog>
<changeSet id="1" author="dev">
<createTable tableName="users">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true"/>
</column>
<column name="email" type="varchar(255)">
<constraints nullable="false" unique="true"/>
</column>
</createTable>
<rollback>
<dropTable tableName="users"/>
</rollback>
</changeSet>
</databaseChangeLog>
Migration Strategies
Expand-Contract Pattern
For backward-compatible changes:
Phase 1: EXPAND
├── Add new column (nullable or with default)
├── Add new table
├── Deploy new code that writes to both old and new
└── Backfill existing data
Phase 2: CONTRACT
├── Remove old column usage from code
├── Make new column non-nullable if needed
├── Drop old column
└── Deploy final code
Example - Renaming a column:
-- Phase 1: Expand
ALTER TABLE users ADD COLUMN full_name VARCHAR(200);
UPDATE users SET full_name = name;
-- Deploy code that reads from both, writes to both
-- Phase 2: Contract (after verification)
ALTER TABLE users DROP COLUMN name;
Blue-Green Deployment
┌─────────────┐ ┌─────────────┐
│ Blue │ │ Green │
│ (Current) │ │ (New) │
└──────┬──────┘ └──────┬──────┘
│ │
└───────┬───────────┘
│
┌──────┴──────┐
│ Database │
│ (Shared) │
└─────────────┘
1. Green environment runs migrations
2. Test Green with new schema
3. Switch traffic Blue → Green
4. Blue becomes standby
Rolling Updates
1. Apply backward-compatible migration
2. Update servers one by one
3. Old code continues working
4. After all servers updated, remove old code paths
5. Apply cleanup migration
Zero-Downtime Patterns
Add Column (Safe)
-- Safe: Column added as nullable
ALTER TABLE users ADD COLUMN phone VARCHAR(20);
-- Safe: Column added with default
ALTER TABLE users ADD COLUMN status VARCHAR(20) DEFAULT 'active';
-- PostgreSQL 11+: Fast default
ALTER TABLE users ADD COLUMN created_at TIMESTAMP DEFAULT NOW();
Add Non-Nullable Column
-- Step 1: Add nullable
ALTER TABLE users ADD COLUMN email_verified BOOLEAN;
-- Step 2: Backfill
UPDATE users SET email_verified = FALSE WHERE email_verified IS NULL;
-- Step 3: Add constraint
ALTER TABLE users ALTER COLUMN email_verified SET NOT NULL;
Rename Column
-- Step 1: Add new column
ALTER TABLE users ADD COLUMN full_name VARCHAR(200);
-- Step 2: Copy data
UPDATE users SET full_name = name;
-- Step 3: Add trigger for sync (during transition)
CREATE TRIGGER sync_name BEFORE INSERT OR UPDATE ON users
FOR EACH ROW EXECUTE FUNCTION sync_name_columns();
-- Step 4: Update application to use new column
-- Step 5: Remove old column
ALTER TABLE users DROP COLUMN name;
DROP TRIGGER sync_name ON users;
Add Index (Non-Blocking)
-- PostgreSQL: CONCURRENTLY
CREATE INDEX CONCURRENTLY idx_users_email ON users(email);
-- MySQL: ALGORITHM=INPLACE, LOCK=NONE
ALTER TABLE users ADD INDEX idx_email (email), ALGORITHM=INPLACE, LOCK=NONE;
-- SQL Server: ONLINE
CREATE INDEX idx_users_email ON users(email) WITH (ONLINE = ON);
Drop Column (Safe)
-- Step 1: Stop writing to column (application change)
-- Step 2: Deploy application
-- Step 3: Drop
Установить migrations в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobWriteEditВложенные файлы
FAQ
Что делает скилл migrations?
Database migration strategies and best practices. Covers schema versioning, zero-downtime migrations, rollback patterns, and data migration techniques. Use for database evolution and deployment planning. USE WHEN: user mentions "database migrations", "schema changes", "versioning", "rollback", "zero-downtime", "expand-contract", "schema evolution" DO NOT USE FOR: Flyway specifics - use `flyway` instead, Prisma migrations - use `prisma` instead, TypeORM migrations - use `typeorm` instead
Как установить скилл migrations?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл migrations запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic