migration-patterns
Database migration patterns for SQLite. Use when creating migrations, modifying schema, or running database changes.
When & Why to Use This Skill
This Claude skill provides standardized database migration patterns for SQLite, streamlining the process of creating migrations, modifying schemas, and managing database versioning. It focuses on industry best practices such as idempotency, structured naming conventions, and clear documentation to ensure reliable, conflict-free, and maintainable database evolution for developers.
Use Cases
- Case 1: Initializing a new SQLite database with a structured version-controlled migration system to track schema changes from day one.
- Case 2: Safely adding new tables or columns to an existing production database using idempotent 'IF NOT EXISTS' patterns to prevent deployment errors.
- Case 3: Standardizing database workflows across a development team by enforcing consistent naming conventions and migration file organization.
- Case 4: Documenting complex schema modifications with clear descriptions and indexes to optimize database performance and maintainability.
| name | migration-patterns |
|---|---|
| description | Database migration patterns for SQLite. Use when creating migrations, modifying schema, or running database changes. |
Migration Patterns
Quick Start
-- migrations/001_add_tags.sql
-- Migration: Add Tags Feature
-- Created: 2025-01-15
-- Description: Adds tags table for organizing contacts
CREATE TABLE IF NOT EXISTS tags (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
name TEXT NOT NULL,
color TEXT NOT NULL,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_tags_user_id ON tags(user_id);
Core Principles
- Dual approach: Create migration in
migrations/+ updateschema.sql - Naming:
{number}_{description}.sql(e.g.,001_add_tags.sql) - Zero-padded numbers: 001, 002, 003 (run alphabetically)
- IF NOT EXISTS: Always use for idempotency
- One feature per migration: Keep focused
- Include indexes: Add in same migration as tables
- Never modify: Once committed, create new migration instead
Reference Files
- migration-guide.md - Complete workflow and examples
- troubleshooting.md - Common issues