Safe Data Backfill
Write a backfill or one-off data migration that is batched, resumable, verifiable, and reversible, with a dry run before anything writes.
Write a data backfill script. What needs to change: [THE TRANSFORMATION, IN PLAIN TERMS] Schema and table sizes: [PASTE THE RELEVANT SCHEMA + ROW COUNTS] Database and version: [e.g. Postgres 16, MySQL 8, MongoDB] Language and access pattern: [e.g. "Python with SQLAlchemy", "a psql script", "a Rails task"] Is the system live during the backfill: [YES/NO. If yes, what writes to these rows concurrently.] Acceptable runtime and load: [e.g. "must not add more than 10% database load", "overnight window of 4 hours"] How rows are identified: [PRIMARY KEY TYPE, whether it is monotonic] The script must: - **Dry run by default.** Running it without an explicit flag reports what it would change, including counts and a sample of before and after values, and writes nothing. - **Batch** with a configurable size, committing per batch. Never one transaction over the whole table, and never row-by-row across a large table. - **Be resumable.** Track progress durably (a cursor table or a marker column) so an interrupted run continues rather than restarting. Make it safe to run twice: reprocessing an already-migrated row must be a no-op, not a second transformation. - **Throttle.** A pause between batches, and a check that backs off when replication lag or load crosses a threshold. Name the specific signal to watch for my database. - **Log** per batch: range processed, rows changed, rows skipped, errors, and elapsed time. Enough to answer "where did it get to" from the logs alone. - **Handle concurrent writes** correctly if the system is live: state the locking or conditional-update strategy and what happens when a row changes between read and write. - **Fail loudly.** On an unexpected row, stop and report rather than skipping silently. A backfill that quietly skips rows is worse than one that stops, because nobody finds out for months. Also produce: 1. **The verification query** that proves the backfill is complete and correct, runnable independently of the script. 2. **The rollback plan**: whether the original values can be recovered, and if not, what to snapshot before starting. Say plainly if this migration is irreversible. 3. **The run plan**: dry run, then a small limited batch, then check, then full run. With the exact commands. Rules: if the transformation is not reversible from the data alone, say so in your first line. Do not write a script that mutates rows in place without a way to know what they were.
How to use
Dry run by default is the requirement that makes everything else usable, because the version of this script that people actually run is the one written at 11pm during an incident. Resumability and idempotence go together: a backfill that cannot be safely rerun turns any interruption into an audit. Insist on the verification query being independent of the script, since a script that reports its own success proves only that it finished.
More coding prompts
Write the commit message for this change. Diff: """ [PASTE THE STAGED DIFF] """ Why I made this change: [THE REASON, THE TICKET, THE BUG REPORT, or "you infer it"] Convention: [Conventional Commits / this repo's existing style, pasted below / plain] Recent commits from this repo, to match style: """ [PASTE 5-10 RECENT COMMIT SUBJECT LIN
Commit Message
Write a commit message that explains why the change was made, in Conventional Commits format, split into separate commits when needed.
Help me recover from a git mistake without making it worse. What I was trying to do: [THE GOAL] What I ran: [THE EXACT COMMANDS, IN ORDER] What happened instead: [THE OUTPUT OR THE STATE NOW] Has this been pushed or shared: [YES/NO, and to which branch and whether anyone else has pulled] Uncommitted work I cannot lose: [WHAT AND WHERE, o
Undo a Git Mistake
Recover from a bad commit, force push, wrong branch, or lost work with a reversible plan and the exact commands, explained before you run them.
Handler code, routes, and models: """ [PASTE THE ROUTE DEFINITIONS, HANDLERS, REQUEST AND RESPONSE TYPES, VALIDATION SCHEMAS, AND MIDDLEWARE] """ Generate an OpenAPI 3.1 specification from the code above. API name, version, and base URL: [DETAILS] Auth scheme: [BEARER JWT / API KEY / OAUTH / SESSION COOKIE, and where it is enforced] Con
OpenAPI Spec From Code
Generate an accurate OpenAPI 3.1 spec from handler code, including error responses and auth, with gaps flagged instead of invented.