Back to cookbook

AI Prompt to Write a Zero-Downtime Database Migration Plan

0 views Updated

Make this prompt yours

Share

This database migration plan prompt is for backend engineers and DevOps teams who need to change a production schema (adding a column, splitting a table, changing a data type) without taking the application offline. Rather than asking for raw migration SQL, it asks the model to produce a sequenced plan built around the standard safe pattern: add the new structure, backfill data, dual-write or read from both paths during a transition window, then cut over and clean up the old structure only once everything is verified.

The prompt deliberately asks for rollback steps at every stage, not just one rollback plan at the end, because the riskiest part of a live migration is usually a partial failure midway through, not a clean failure at the start. It also asks the model to flag any step that would lock a table or block writes for more than a moment, since that's the detail most likely to turn a "zero-downtime" migration into an outage if it's missed.

For migrations big enough that the full plan runs long, Cuelara's Token Optimizer can compress the prompt and its context before you send it to an API-based workflow, which keeps repeated runs (one per environment, for example) from costing more tokens than they need to.

Prompt template

Make this prompt yours

prompt-template
322 tokens
ROLE: You are a senior database engineer who specializes in zero-downtime production migrations. CONTEXT: - Database engine and version: [e.g. PostgreSQL 15, MySQL 8] - Table(s) involved and approximate row count: [TABLE NAME(S) AND SIZE] - Current schema (relevant columns): [PASTE RELEVANT SCHEMA] - Desired change: [e.g. add a NOT NULL column with a default, split a table, change a column's data type] - Traffic pattern: [e.g. high read volume, moderate writes, peak hours] - Application framework/ORM if relevant: [FRAMEWORK NAME] TASK: 1. Propose a staged migration plan using the expand-and-contract pattern (add new structure, backfill, dual-write/read, cut over, clean up). 2. For each stage, specify: the exact change, whether it requires a lock or maintenance window, how to verify it succeeded, and the rollback step if it fails. 3. Flag any stage where failure could leave the system in an inconsistent state, and how to detect that. 4. Note the order in which application code changes and database changes must deploy relative to each other. CONSTRAINTS: - Assume this runs against a live production system with zero acceptable downtime - Call out any step, however small, that would lock the table or block writes - Do not combine the cutover and cleanup stages into a single deployment OUTPUT FORMAT: Stage-by-stage table or list: Stage Name → Change → Lock/Downtime Risk → Verification → Rollback

Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.

Example input

example-input
97 tokens
Database engine and version: PostgreSQL 14 Table(s) involved and approximate row count: orders table, ~40 million rows Current schema (relevant columns): orders(id, user_id, status, created_at) Desired change: add a NOT NULL column `region` with no default, backfilled from a lookup against the users table Traffic pattern: high read volume throughout the day, writes concentrated during business hours Application framework/ORM if relevant: Rails with ActiveRecord

When to use it

  • You're changing a production database schema and the application cannot have downtime
  • You're splitting, renaming, or changing the type of a column that's actively read and written by live traffic
  • You need a plan reviewable by a second engineer before running anything against production
  • You're migrating between two database engines or table structures and need a staged cutover, not a single cutover event

Best practices

  • Describe your actual database engine, table size, and read/write patterns, since the safe approach for a 10,000-row table differs from a 500-million-row one
  • Ask explicitly for which steps can run concurrently with normal traffic versus which require a maintenance window, however short
  • Request a rollback step after every stage, not just a single rollback plan at the end, so a partial failure has a clear recovery path
  • Have a second engineer review the plan's locking behavior before running it, since even a correct-looking migration can still take an unexpected table lock under real load

Common mistakes

  • Asking only for the migration SQL and skipping the backfill, dual-write, and cutover stages that actually prevent downtime
  • Running the full plan against production without first testing it against a realistic copy of the data, including its size
  • Dropping the old column or table in the same deployment as the cutover instead of leaving a verification window in between
  • Assuming a plan is zero-downtime just because it was labeled that way, without checking which individual steps take locks

FAQs

What does zero-downtime database migration mean?

It means changing a production database's schema without taking the application offline or blocking reads and writes for more than a brief moment, typically by staging the change across multiple deploys instead of one.

What is the expand-and-contract pattern in database migrations?

It's a staged approach where you first add new schema alongside the old (expand), run both in parallel while verifying the new path, then remove the old schema only after the new one is fully trusted (contract), avoiding a single risky cutover.

Can AI write migration SQL that's safe to run directly against production?

AI-generated migration plans and SQL should always be reviewed by an engineer familiar with the actual table size, traffic pattern, and database engine version before running against production, since locking behavior varies significantly between engines and versions.

Which Cuelara tool helps with long or repeated migration prompts?

Token Optimizer — compresses a verbose migration prompt and its schema context, which helps when you're running similar prompts across multiple environments or services and want to cut API token costs.

Found this prompt useful? Share it.

Share

More in Engineering

Engineering

AI Prompt to Triage Flaky CI Test Failures Using GitHub's MCP Server

This AI prompt helps engineers and tech leads figure out which failing CI tests are genuine bugs and which are flaky tests that fail intermi…

Role: You are a CI reliability engineer helping triage test failures.

Context:
- Repository: [REPO_NAME]
- Failing test(s): [TEST_NAME_OR_FILE]
- Workflow or CI pipeline: [WORKFLOW_NAME]
- Number of recent runs to review: [NUMBER_OF_RUNS, e.g. 15]
- Approximate time the failures started: [DATE_OR_COMMIT_RANGE]

Task:
1. Retrieve the run history for the specified test across the last [NUMBER_OF_RUNS] workflow runs.
2. For each run, note whether the test passed or failed, and if it failed, record the exact failure message and stack trace line.
3. Determine whether the failure message and location are consistent across failing runs or vary from run to run.
4. Identify the commits merged in the window right before the failures began and flag any that touch the same files, dependencies, or test fixtures as the failing test.
5. Classify the failure as either "Likely flaky" (intermittent, inconsistent messages, no related code change) or "Likely real regression" (consistent failure tied to a specific commit).

Constraints:
- Do not classify a test as flaky without at least 3 failed runs to support it.
- Always name the specific commit(s) you suspect if classifying as a real regression.
- State your confidence level (high, medium, low) for the classification.

Output format:
Test: [name]
Classification: [Likely flaky / Likely real regression]
Confidence: [high/medium/low]
Evidence: [run-by-run summary]
Suspect commit(s), if any: [commit hash and message]
Recommended next step: [one sentence]

Make this prompt yours

Engineering

AI Prompt to Generate Release Notes From Jira Tickets Using Atlassian's MCP Server

This Jira MCP prompt turns a list of completed tickets into a readable set of release notes , built for engineering managers, release manage…

ROLE: You are a release notes writer working from live Jira data retrieved through an MCP connection.

CONTEXT:
- Jira project key: [PROJECT_KEY]
- Fix version or sprint to summarize: [FIX_VERSION_OR_SPRINT]
- Audience for these notes: [AUDIENCE, e.g. end users, internal team, enterprise customers]
- Tone: [TONE, e.g. plain and professional, upbeat and casual]

TASK:
1. Retrieve all tickets in [PROJECT_KEY] tagged with fix version or sprint [FIX_VERSION_OR_SPRINT] via the connected Jira MCP server.
2. Group the tickets into exactly these sections: "New Features", "Improvements", "Bug Fixes", and "Internal Changes (not customer-facing)".
3. For each ticket, write one short sentence in plain language describing what changed and why it matters to [AUDIENCE] — do not copy the raw ticket title verbatim.
4. Exclude the "Internal Changes" section from the customer-facing version if [AUDIENCE] is external; include it only in the internal version.
5. Flag any ticket labeled "security", "breaking-change", or with no description under a separate "Needs Manual Review" heading instead of guessing at its content.

CONSTRAINTS:
- Do not invent functionality that isn't described in the ticket data.
- Do not include Jira ticket keys in the customer-facing version; keep them in the internal version for traceability.
- Keep each bullet to one sentence unless the change is a breaking change, which gets two sentences: what changed and what action is required.

OUTPUT FORMAT:
Return the release notes as Markdown with the four section headings above (omitting empty sections), followed by a "Needs Manual Review" list if applicable.

Make this prompt yours

Engineering

AI Prompt to Triage and Prioritize Engineering Issues Using Linear's MCP Server

This Linear MCP prompt helps engineering leads, team leads, and project managers use an AI assistant connected to Linear's Model Context Pro…

ROLE
You are an engineering triage assistant with access to a Linear workspace through its MCP server integration.

CONTEXT
Team or project: [TEAM_OR_PROJECT_NAME]
Time window: issues updated or opened in the last [TIME_WINDOW]
Priority scale in use: [PRIORITY_SCALE_DEFINITION]
Current sprint or cycle goal: [SPRINT_GOAL]

TASK
1. Pull all open issues matching the team, project, and time window above through the Linear MCP connection.
2. Group the issues into: blocked, in progress, and not started.
3. For each issue, assess severity using this rubric: [SEVERITY_RUBRIC], customer or revenue impact, how long it has been open, and whether it blocks other issues.
4. Flag any issue missing a priority, assignee, or label, and list it separately as a hygiene issue rather than ranking it.
5. Produce a prioritized list of the top [NUMBER] issues the team should work on next, with a one-line justification for each ranking.
6. Note any issues that appear to duplicate each other or contradict the stated sprint goal.

CONSTRAINTS
- Do not invent issue data that is not present in the Linear workspace; if a field is missing, say so explicitly.
- Keep each justification to one sentence.
- Do not take any write actions (status changes, reassignments) unless I explicitly confirm each one.

OUTPUT FORMAT
1. Hygiene issues (missing priority, assignee, or label) - bullet list
2. Blocked issues - bullet list with blocker noted
3. Prioritized list of top [NUMBER] issues - numbered, with one-line justification each
4. Possible duplicates or conflicts with sprint goal - bullet list

Make this prompt yours