.claude/skills/the-migrator/SKILL.md
Creates and runs data migrations for schema changes, ensuring data integrity.
npx skillsauth add dupipcom/morpheus the-migratorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Task: Create data migration scripts for schema changes and execute them safely.
Role: You're a database migration specialist ensuring smooth data transitions without data loss.
Analyze schema changes
Create migration script
src/migrations/Test in development
# Test migration
npx ts-node src/migrations/YYYY-MM-DD-description.ts
Verify data integrity
// src/migrations/YYYY-MM-DD-description.ts
import prisma from '../lib/prisma'
const BATCH_SIZE = 100
const DRY_RUN = process.env.DRY_RUN === 'true'
async function migrate() {
console.log(`Starting migration... (DRY_RUN: ${DRY_RUN})`)
let processed = 0
let updated = 0
let errors = 0
// Count total records
const total = await prisma.collection.count()
console.log(`Total records to process: ${total}`)
// Process in batches
let skip = 0
while (true) {
const batch = await prisma.collection.findMany({
take: BATCH_SIZE,
skip,
orderBy: { id: 'asc' }
})
if (batch.length === 0) break
for (const record of batch) {
try {
// Transform data
const transformed = transformRecord(record)
if (!DRY_RUN) {
await prisma.collection.update({
where: { id: record.id },
data: transformed
})
}
updated++
} catch (error) {
console.error(`Error processing ${record.id}:`, error)
errors++
}
processed++
}
skip += BATCH_SIZE
console.log(`Progress: ${processed}/${total} (${Math.round(processed/total*100)}%)`)
}
console.log(`
Migration complete:
- Processed: ${processed}
- Updated: ${updated}
- Errors: ${errors}
`)
}
function transformRecord(record: any) {
// Implement transformation logic
return {
// transformed fields
}
}
// Run migration
migrate()
.catch(console.error)
.finally(() => prisma.$disconnect())
// Rename 'oldField' to 'newField'
await prisma.$runCommandRaw({
update: 'Collection',
updates: [{
q: { oldField: { $exists: true } },
u: { $rename: { 'oldField': 'newField' } },
multi: true
}]
})
// Convert string to number
const transformed = {
amount: parseFloat(record.amount) || 0
}
// Flatten nested structure
const transformed = {
name: record.data?.name || record.name,
visibility: record.data?.visibility ?? true
}
// Add missing fields with defaults
if (!record.visibility) {
transformed.visibility = 'PRIVATE'
}
DRY_RUN=true first to preview changesAfter migration:
# Verify schema matches data
npx prisma db push
# Regenerate client
npx prisma generate
Each migration should document:
development
Runs tests, analyzes failures, and fixes test issues to ensure code quality.
tools
Identifies and fixes performance bottlenecks in the application.
development
Identifies and fixes ESLint errors and TypeScript type issues across the codebase.
tools
Manages internationalization - adds translations, fixes missing keys, and ensures locale consistency.