$ recombobulate _
home / tips / ask-claude-to-write-data-migration-scripts-for-backfills-and-cleanups
149

Ask Claude to Write Data Migration Scripts for Backfills and Cleanups

recombobulate @recombobulate · Mar 29, 2026 · Workflows
ask-claude-to-write-data-migration-scripts-for-backfills-and-cleanups

Schema migrations change your database structure. Data migrations change what's in it — and they're harder to get right because bad data transforms are hard to undo. Claude reads your schema and writes scripts that handle the edge cases.

Write a data migration that backfills the new 'full_name' column 
from the existing 'first_name' and 'last_name' columns. Handle nulls, 
empty strings, and names with multiple spaces. Process in batches of 1000.

Claude reads your model and writes a script that handles the edge cases you'd forget:

// Claude generates framework-appropriate batch processing
User::whereNull('full_name')
    ->chunkById(1000, function ($users) {
        foreach ($users as $user) {
            $parts = array_filter([
                $user->first_name,
                $user->last_name,
            ]);
            $user->update([
                'full_name' => implode(' ', $parts) ?: null,
            ]);
        }
    });

This works for all kinds of data transformations:

# Clean up inconsistent data
Find all phone numbers in the users table that aren't in E.164 format 
and normalise them. Log any that can't be parsed.

# Merge duplicates
Find duplicate users by email (case-insensitive). Keep the one with the 
most recent login, merge the order history from the others, then soft-delete 
the duplicates.

# Split a column
The 'address' field contains freetext addresses. Parse them into 
street, city, state, and postcode columns. Flag any that can't be 
parsed reliably for manual review.

# Encrypt sensitive data
Write a migration that encrypts all plain-text SSN values in the 
customers table using the app's encryption key. Make it idempotent 
so it can be re-run safely.

Always ask Claude to make the script safe:

Make this data migration:
- Idempotent (safe to run twice)
- Batched (don't load the whole table into memory)
- Logged (report progress every 1000 records)
- Reversible if possible (store the old values somewhere)

Schema migrations are well-tooled. Data migrations are where things go wrong — let Claude handle the edge cases, batching, and safety checks you'd skip if you wrote it yourself.

via Claude Code

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Run Claude Code in GitHub Actions to Automatically Review Every Pull Request

Set up Claude Code as an automated reviewer in your CI pipeline — on every pull request, it reads the diff, checks for bugs, security issues, missing tests, and convention violations, then posts its findings as a PR comment. Your human reviewers get a head start because the obvious issues are already flagged before they look.

recombobulate @recombobulate · 1 day ago
0
Ask Claude to Build a Deployment Checklist from Your Actual Infrastructure

Before deploying, tell Claude to read your project — migrations, environment variables, queue workers, scheduled tasks, caching, third-party integrations — and generate a deployment checklist that's specific to your app. Not a generic "did you run migrations?" list, but one that knows YOUR infrastructure and catches the things YOUR deploy can break.

recombobulate @recombobulate · 1 day ago
0
Ask Claude to Generate a README from Your Actual Codebase — Not a Template

Instead of writing a README from memory or copying a template, tell Claude to read your project and generate one that's actually accurate — real setup instructions from your config, real architecture from your directory structure, real API examples from your routes, and real prerequisites from your dependency files.

recombobulate @recombobulate · 1 day ago