Squire Migrate
Execute a multi-step infrastructure migration with rollback safety, automatic config updates, full verification, and det
git clone https://github.com/eddiebelaval/squire
skills/migrate/skill.mdMigrate — Autonomous Infrastructure Migration Pipeline
Core Workflows
Workflow 1: Primary Action
- Analyze the input and context
- Validate prerequisites are met
- Execute the core operation
- Verify the output meets expectations
- Report results
Execute a multi-step infrastructure migration with rollback safety, automatic config updates, full verification, and detailed logging. No confirmation prompts — runs end-to-end and reports results.
Usage
/migrate "Move auth schema from Supabase project homer-dev to homer-prod" /migrate "Consolidate two Supabase projects into one, update all .env files" /migrate "Switch from Redis Cloud to Upstash, update all connection strings" /migrate "Move from Vercel Postgres to Supabase, migrate schema and data"
The argument is a plain-English description of the migration. Be specific about source, destination, and what's moving.
Instructions
When invoked with a migration description:
Step 0: Initialize
- Identify the project(s) involved from the current directory and the migration description.
- State: "Migration: [DESCRIPTION] | Project: [PROJECT] | Branch: [BRANCH]"
- Create
in the project root:MIGRATION_LOG.md# Migration Log — {date} **Goal:** {migration description} **Started:** {timestamp} **Status:** IN PROGRESS --- - Every action taken from this point forward gets logged to MIGRATION_LOG.md with a timestamp and result.
Step 1: Audit Current State
Before touching anything, build a complete picture:
-
Find all env files across the repo:
.env, .env.local, .env.development, .env.production, .env.testAlso check:
,vercel.json
,next.config.js/ts
, CI/CD configs.docker-compose.yml -
Catalog every connection string, API key, and URL that relates to the migration:
- Database URLs (Supabase, Postgres, Redis)
- API keys and service tokens
- Webhook URLs
- CDN or storage bucket references
-
Check active connections:
- Can we reach the source? (curl, pg_isready, or equivalent)
- Can we reach the destination? (same checks)
- Are there active sessions or locks?
-
Map dependencies:
- Which source files import or reference the affected services?
- Which config files need updating?
- Are there migration files, seed scripts, or schema definitions?
-
Log the complete audit to MIGRATION_LOG.md under
.## Step 1: Audit
Output to the user:
Audit Complete ============== Env files found: {N} Connection strings to update: {N} Source reachable: YES/NO Destination reachable: YES/NO Files referencing old config: {list}
If source or destination is unreachable, log the error and attempt to diagnose (wrong URL, missing credentials, network issue). Fix if possible. If not fixable, STOP and report — do not proceed with a broken connection.
Step 2: Create Rollback Safety Net
Before making any changes:
-
Dump the source schema (if database migration):
# For Supabase/Postgres pg_dump --schema-only -d "{SOURCE_URL}" > migration_rollback_schema.sql pg_dump -d "{SOURCE_URL}" > migration_rollback_full.sql # if data tooIf
is not available, use Supabase CLI or MCP to export.pg_dump -
Snapshot all env files:
mkdir -p .migration-backup cp .env* .migration-backup/ 2>/dev/null cp vercel.json .migration-backup/ 2>/dev/null -
Create a git stash or checkpoint:
git stash push -m "pre-migration checkpoint"Or if working tree is clean, tag the current commit:
git tag pre-migration-{timestamp} -
Log all backup locations to MIGRATION_LOG.md under
.## Step 2: Rollback Safety
Step 3: Execute Migration
This step varies by migration type. Apply the appropriate sub-procedure:
Database Migration (Supabase/Postgres)
- Apply schema to destination (use dumped schema or Supabase migrations)
- Migrate data if required (pg_dump/pg_restore, or INSERT...SELECT via dblink)
- Verify row counts match between source and destination
- Verify foreign keys and constraints are intact
- Run any seed scripts if needed
Service Migration (Redis, Storage, CDN)
- Export data from source service
- Import data to destination service
- Verify data integrity (key counts, checksums)
Config-Only Migration (URL/key swap)
- Skip directly to Step 4
For each action: Log to MIGRATION_LOG.md with result (success/failure).
On failure: Diagnose the issue. Common fixes:
- Permission denied → Check service role vs anon key
- Schema conflict → Drop and recreate (destination only, NEVER source)
- Data type mismatch → ALTER column or cast during transfer
- Timeout → Retry with smaller batch size
If a fix is applied, log it and continue. Do NOT stop unless data loss is possible.
Step 4: Update All Config Files
For every connection string, API key, or URL identified in the audit:
-
Replace old values with new values in all env files.
-
Update source code that hard-codes connection details (find with Grep).
-
Update infrastructure configs: vercel.json, docker-compose, CI/CD.
-
Update Vercel environment variables if the project deploys to Vercel:
# Read new value, update Vercel vercel env rm {VAR_NAME} production vercel env add {VAR_NAME} production < <(echo "{NEW_VALUE}")Only do this if user has Vercel CLI configured and the project uses Vercel.
-
Log every file changed to MIGRATION_LOG.md under
.## Step 4: Config Updates
CRITICAL: Never log actual secrets to MIGRATION_LOG.md. Use placeholders:
Updated .env.local: SUPABASE_URL changed from [old-project].supabase.co to [new-project].supabase.co
Step 5: Verify Everything Works
Run the full verification suite:
- Type check:
npx tsc --noEmit - Build:
npm run build - Unit tests:
npm test - E2E tests:
(if available)npx playwright test - Connectivity check: Verify the app can reach the new service:
- Start dev server briefly and check a health endpoint, OR
- Run a simple connection test script
If any check fails:
- Diagnose the root cause
- Fix it (update config, fix import, adjust type)
- Re-run the failing check
- Log the fix to MIGRATION_LOG.md
- Maximum 3 fix attempts per failure before marking as unresolved
Step 6: Commit and Report
-
Clean up backup files (remove .migration-backup directory — it's in git stash already).
-
Stage all changed files.
-
Commit:
feat: migrate {source} to {destination} - Schema migrated: {yes/no} - Data migrated: {yes/no} - Config files updated: {N} - Tests: {PASS/FAIL} - Build: {PASS/FAIL} See MIGRATION_LOG.md for full details. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> -
Finalize MIGRATION_LOG.md:
--- **Completed:** {timestamp} **Status:** COMPLETE (or COMPLETE WITH WARNINGS) **Duration:** {time} ## Summary - Files modified: {list} - Services migrated: {list} - Tests: PASS/FAIL - Build: PASS/FAIL - Unresolved issues: {list or "None"} ## Rollback Instructions To revert this migration: 1. git stash pop (or git revert {commit}) 2. Restore .env files from .migration-backup 3. {any service-specific rollback steps} -
Output summary to user:
Migration Complete ================== Goal: {description} Duration: {time} Schema: {migrated/skipped} Data: {migrated/skipped} Config files updated: {N} Type check: PASS/FAIL Build: PASS/FAIL Tests: PASS/FAIL Rollback: git stash pop OR git revert HEAD Full log: MIGRATION_LOG.md -
Do NOT push to remote. Do NOT delete the git tag/stash.
Safety Rules
| Rule | Why |
|---|---|
| Never modify source database destructively | Source is the fallback if destination fails |
| Never log secrets to MIGRATION_LOG.md | Log files get committed |
| Always create rollback checkpoint first | One command to undo everything |
| Verify destination connectivity before writing | Don't write config pointing to unreachable service |
| Never push to remote | User decides when migration is ready to ship |
| Stop if data loss is possible | Ask user instead of risking irreversible damage |
What This Skill Does NOT Do
- Delete source databases or services (you decommission manually)
- Push to remote or deploy
- Modify production environment variables without Vercel CLI confirmation
- Migrate data larger than what fits in a single pg_dump (flag and ask)
- Handle multi-region or distributed system migrations (too complex for autonomous execution)