Inferensys

Prompt

Database Schema Migration Test Selection Prompt

A practical prompt playbook for using Database Schema Migration Test Selection Prompt in production AI workflows.
Developer doing prompt engineering on laptop, prompt variations visible on screen, casual coding session.
PROMPT PLAYBOOK

When to Use This Prompt

Understand the job-to-be-done, the ideal user, and the specific conditions under which this prompt provides safe, auditable value for database schema migration testing.

This prompt is designed for data engineers, DBAs, and release managers who are planning a database schema migration and need a targeted, risk-based regression test plan. It takes a migration specification, current schema, and dependency map as input, then produces a prioritized list of tests covering data integrity, backward compatibility, rollback verification, referential integrity, constraint validation, and performance regression checks. Use this prompt when you need an auditable, rationale-backed test selection that reduces full-suite runtime while maintaining safety coverage for schema changes.

The ideal workflow involves feeding the prompt a structured migration spec (DDL diff or migration file), the current full schema DDL, and a dependency map showing which application modules, views, or stored procedures reference the affected objects. The prompt then reasons about impact propagation—for example, a column type change on a heavily referenced table should trigger tests for all dependent views and application queries, not just the table itself. The output is a test list with explicit rationales, making it suitable for compliance review and audit trails where you must demonstrate that testing was risk-driven rather than arbitrary.

Do not use this prompt for application-layer code changes, infrastructure-as-code diffs, or general release readiness assessments without a schema change component. It is not designed to evaluate business logic correctness, UI behavior, or API contract changes unless those changes are direct consequences of the schema migration. For those scenarios, use the sibling prompts in this category, such as the Change-Based Regression Test Selection Prompt or the API Endpoint Change Impact Assessment Prompt. Always pair the output with human review for migrations involving financial data, PII, or irreversible destructive operations like column drops or table truncations.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Database Schema Migration Test Selection Prompt delivers value and where it introduces risk. Use these cards to decide if this prompt fits your migration workflow.

01

Good Fit: Structured Schema Diffs

Use when: You have a machine-readable migration script (DDL diff) or a well-documented changelog. The prompt excels at mapping ALTER TABLE, ADD CONSTRAINT, or DROP COLUMN statements to specific test categories. Guardrail: Always provide the full DDL diff as [SCHEMA_CHANGES]—partial diffs produce incomplete test coverage.

02

Bad Fit: Undocumented Legacy Migrations

Avoid when: The migration is a manual, ad-hoc process with no source of truth for the target schema. The prompt cannot infer missing constraints, implicit data type coercions, or undocumented triggers. Guardrail: Require a human DBA to document the intended schema state before invoking the prompt; otherwise, generated tests will have dangerous blind spots.

03

Required Inputs

Required: [SCHEMA_CHANGES] (full DDL diff), [DATABASE_TYPE] (PostgreSQL, MySQL, etc.), and [MIGRATION_CONTEXT] (rollout plan, rollback strategy). Optional but critical: [EXISTING_TEST_SUITE] for deduplication and [DATA_VOLUME_ESTIMATE] for performance test scoping. Guardrail: Missing [MIGRATION_CONTEXT] causes the prompt to skip rollback and backward-compatibility tests.

04

Operational Risk: False Confidence in Coverage

Risk: The prompt produces a comprehensive-looking test list that may miss environment-specific issues (connection pooling, replica lag, storage engine behavior). Guardrail: Treat the output as a starting point. Always append manual checks for infrastructure-specific failure modes and run a smoke test on a staging clone before production.

05

Operational Risk: Constraint Validation Gaps

Risk: The prompt may generate referential integrity tests for explicitly declared foreign keys but miss application-enforced constraints or cross-database references. Guardrail: Pair this prompt with a manual review of application-level data integrity rules. Add custom test cases for any constraint not visible in the DDL.

06

When to Escalate to a Human DBA

Escalate when: The migration involves data type changes that may truncate or silently coerce data, partition reorganization, or replication topology changes. The prompt cannot assess production data quality risks. Guardrail: Flag any test case involving destructive operations (DROP, TRUNCATE, type coercion) for mandatory human approval before execution.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A reusable prompt with square-bracket placeholders that you adapt to your migration context before sending to the model.

This prompt template is designed to produce a structured, risk-aware test selection for a database schema migration. It forces the model to reason about data integrity, backward compatibility, rollback safety, and performance before listing specific test cases. Replace each square-bracket placeholder with concrete details from your migration plan. The more precise your inputs—especially the migration DDL, current schema, and data volume estimates—the more actionable the output will be.

text
You are a database reliability engineer reviewing a planned schema migration. Your task is to produce a test selection that covers data integrity, backward compatibility, rollback verification, and performance regression checks.

## Migration Context
- Migration DDL: [MIGRATION_DDL]
- Current Schema (relevant tables): [CURRENT_SCHEMA_DDL]
- Migration Type: [MIGRATION_TYPE] (e.g., add column, rename column, split table, change data type, add constraint)
- Estimated Table Sizes: [TABLE_ROW_COUNTS]
- Application Read/Write Patterns During Migration: [ACCESS_PATTERNS]
- Downtime Tolerance: [DOWNTIME_WINDOW]
- Rollback Plan: [ROLLBACK_PLAN]

## Output Schema
Return a JSON object with the following structure:
{
  "risk_assessment": {
    "data_loss_risk": "low|medium|high|critical",
    "downtime_risk": "low|medium|high|critical",
    "rollback_complexity": "low|medium|high|critical",
    "summary": "string"
  },
  "test_categories": [
    {
      "category": "data_integrity|backward_compatibility|rollback|performance|constraint_validation|referential_integrity",
      "tests": [
        {
          "test_name": "string",
          "objective": "string",
          "preconditions": ["string"],
          "steps": ["string"],
          "expected_result": "string",
          "risk_if_skipped": "low|medium|high|critical",
          "automation_feasibility": "high|medium|low|manual_only"
        }
      ]
    }
  ],
  "execution_order": ["test_name"],
  "rollback_tests": [
    {
      "test_name": "string",
      "rollback_step_validated": "string",
      "verification_query": "string"
    }
  ],
  "performance_regression_checks": [
    {
      "query_or_operation": "string",
      "baseline_metric": "string",
      "acceptable_threshold": "string",
      "measurement_method": "string"
    }
  ],
  "constraints_and_referential_integrity_checks": [
    {
      "constraint_name": "string",
      "validation_query": "string",
      "expected_outcome": "string"
    }
  ]
}

## Constraints
- Every test must include a clear verification query or check, not just a description.
- Rollback tests must validate both the rollback procedure and post-rollback data correctness.
- Flag any test that requires a production-sized data volume to be meaningful.
- If the migration changes a column type, include tests for overflow, truncation, and encoding issues.
- If foreign keys are affected, include referential integrity tests for both parent and child tables.
- Mark any test that cannot be automated as "manual_only" with a justification in the objective.
- Do not recommend skipping tests that protect against data loss.

Adapt this template by filling in the migration DDL exactly as it will be executed, including any intermediate steps if the migration spans multiple statements. For the current schema, include only the tables, columns, constraints, and indexes directly affected or referenced by the migration—providing the entire schema can dilute the model's focus. When estimating table row counts, use order-of-magnitude approximations if exact numbers are unavailable, but be explicit about the uncertainty. The access patterns field should describe whether reads and writes continue during the migration, which application paths touch the affected tables, and whether any queue or batch processes might interfere. If you lack a formal rollback plan, state that explicitly rather than omitting the field; the model will then generate rollback tests that also serve as a rollback plan draft. After receiving the output, validate that every test includes a concrete verification step before integrating the results into your test management system.

IMPLEMENTATION TABLE

Prompt Variables

Inputs the prompt needs to produce a reliable database migration test list. Validate each before calling the model; missing or malformed inputs cause the prompt to hallucinate risks or skip critical checks.

PlaceholderPurposeExampleValidation Notes

[MIGRATION_DDL]

The full DDL script (CREATE, ALTER, DROP) to be analyzed

ALTER TABLE orders ADD COLUMN tax_rate DECIMAL(5,4) NOT NULL DEFAULT 0.0000;

Parse check: must contain at least one DDL statement. Reject empty or comment-only input. Schema check: validate against target SQL dialect.

[CURRENT_SCHEMA_SNAPSHOT]

The pre-migration schema as DDL or a structured catalog of tables, columns, indexes, and constraints

Table: orders (id PK, total DECIMAL, ...); FK: orders.user_id -> users.id

Parse check: must include all objects referenced in [MIGRATION_DDL]. Null allowed only for greenfield deployments. If null, set [IS_GREENFIELD] to true.

[DATA_VOLUME_ESTIMATE]

Approximate row counts for affected tables to assess performance test scope

orders: 12M rows, order_items: 45M rows

Format check: table_name: integer rows. Required for tables with ALTER or UPDATE operations. Null allowed if migration is DDL-only with no data movement.

[ROLLBACK_PLAN]

The intended rollback strategy or DDL to reverse the migration

DROP COLUMN tax_rate; or snapshot restore from backup-2025-03-15

Parse check: must be a valid reversal of [MIGRATION_DDL]. If null, prompt must flag rollback test cases as blocked and require manual approval.

[DEPENDENT_SERVICE_LIST]

List of downstream services, ETL jobs, or reports that read from affected tables

billing-service, nightly-revenue-report, data-warehouse-connector

Format check: comma-separated or JSON array. Null allowed. If null, prompt must add a warning that consumer impact analysis was skipped.

[CONSTRAINT_CATALOG]

Existing constraints (PK, FK, UNIQUE, CHECK, NOT NULL) on affected tables

orders: PK(id), FK(user_id->users.id), CHECK(total>=0)

Parse check: must cover all tables in [MIGRATION_DDL]. If null, prompt must note that constraint validation tests are limited to DDL-declared constraints only.

[HISTORICAL_TEST_EXECUTION_TIMES]

Average runtime of existing regression test suites for time-budgeting recommendations

integration-tests: 45m, performance-tests: 2h, unit-tests: 8m

Format check: suite_name: duration. Null allowed. If null, prompt must skip runtime estimates and note that time-budgeted selection is unavailable.

[COMPLIANCE_REQUIREMENT_TAGS]

Regulatory or audit requirements that apply to the data being migrated

SOX, GDPR, PCI-DSS

Format check: comma-separated tag list. Null allowed. If null, prompt must add a disclaimer that compliance-specific test cases were not generated.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the Database Schema Migration Test Selection Prompt into a reliable application or CI/CD workflow.

This prompt is designed to be called programmatically as part of a migration planning or release gate pipeline, not as a one-off chat interaction. The primary integration point is after a migration script has been written and reviewed but before it is applied to any environment beyond a developer sandbox. The application layer should assemble the required inputs—the full DDL diff, the migration script, the target database version, and any known risk constraints—into the prompt's [MIGRATION_SCRIPT], [SCHEMA_DIFF], [DATABASE_VERSION], and [RISK_CONSTRAINTS] placeholders. Because the output is a structured test list, the harness must validate that the model returns a parseable JSON array of test case objects, each containing the required fields (test_id, test_name, test_category, test_objective, test_steps, expected_result, risk_level, rollback_test). If the output fails schema validation, the harness should retry with a stricter [OUTPUT_SCHEMA] constraint or escalate for human review rather than silently accepting a malformed test plan.

For production use, implement a validation layer that checks semantic correctness beyond JSON structure. Confirm that each returned test case maps to a specific clause in the migration script or schema diff—a test that cannot be traced back to a concrete change is a hallucination risk. Validate that referential integrity tests cover all foreign key relationships present in the diff, that rollback tests exist for every destructive operation (DROP, TRUNCATE, ALTER COLUMN type changes), and that performance regression tests reference specific queries or indexes affected by the migration. Log every prompt invocation with the input diff hash, the model version, the output test count, and the validation result. This audit trail is essential when a migration causes a production incident and the team needs to determine whether the test selection was adequate. For high-risk migrations—those involving financial data, PII, or irreversible schema changes—route the generated test list through a human DBA review step before the harness marks it as approved.

Model choice matters here. Use a model with strong SQL and database internals understanding, such as Claude 3.5 Sonnet or GPT-4o, and set a low temperature (0.0–0.2) to maximize deterministic, repeatable test selection. If your migration scripts contain proprietary schema details, run this prompt against a self-hosted or private deployment rather than a public API. The harness should also enforce a maximum test count constraint—if the model returns more than 50 test cases, re-invoke with a tighter [CONSTRAINTS] block asking for the highest-risk subset only, because an overly large test list often indicates the model is enumerating generic checks rather than migration-specific ones. Finally, integrate the validated test list into your test execution system (e.g., by generating a pytest or JUnit suite) and track which tests pass or fail against the migration. Feed those results back into future prompt invocations as [HISTORICAL_FAILURE_DATA] to improve risk-weighted selection over time.

IMPLEMENTATION TABLE

Expected Output Contract

Validate the model's response against this contract before passing it to the test orchestrator. Each field must be parseable and conform to the stated rules.

Field or ElementType or FormatRequiredValidation Rule

test_selections

Array of objects

Array length >= 1. Each element must match the TestSelection schema below.

test_selections[].test_id

String

Non-empty string matching the pattern [TEST_SUITE_ID]-[TEST_CASE_ID] from the input test catalog.

test_selections[].test_name

String

Non-empty string. Must exactly match the test name in the input test catalog for the given test_id.

test_selections[].priority

String

One of: 'P0-Mandatory', 'P1-High', 'P2-Medium', 'P3-Low'. P0 tests must include at least one data integrity or rollback check.

test_selections[].selection_rationale

String

Non-empty string between 20 and 300 characters. Must reference a specific migration risk from the [MIGRATION_PLAN] input.

test_selections[].risk_if_skipped

String

Non-empty string between 20 and 300 characters. Must describe a concrete failure mode, not a generic statement.

test_selections[].estimated_runtime_seconds

Integer

Positive integer. Must be <= the per-test timeout defined in [TEST_ENVIRONMENT_CONFIG].

excluded_tests

Array of objects

Array length >= 0. Each element must match the ExcludedTest schema below.

excluded_tests[].test_id

String

Non-empty string matching a test_id present in the input test catalog but absent from test_selections.

excluded_tests[].exclusion_reason

String

Non-empty string between 10 and 200 characters. Must explain why the test is not relevant to this migration.

rollback_validation_tests

Array of strings

Array length >= 1. Each string must be a test_id from test_selections with priority 'P0-Mandatory'.

backward_compatibility_tests

Array of strings

Array length >= 1. Each string must be a test_id from test_selections that validates the previous schema version.

total_estimated_runtime_seconds

Integer

Sum of all test_selections[].estimated_runtime_seconds. Must be <= [MAX_RUNTIME_BUDGET_SECONDS] if provided.

coverage_summary

Object

Must contain keys: 'data_integrity', 'performance', 'rollback', 'compatibility'. Each value is an integer count of tests covering that category.

PRACTICAL GUARDRAILS

Common Failure Modes

What breaks first when using an LLM to select migration tests and how to guard against it.

01

Hallucinated Schema Objects

What to watch: The model invents table names, column names, or constraint names that don't exist in the actual schema. This produces a test list that references phantom objects, wasting execution cycles and eroding trust. Guardrail: Always provide the exact DDL as context and instruct the model to quote schema object names verbatim. Post-process the output against a system catalog lookup and reject any test referencing an unknown object.

02

Ignoring Implicit Dependencies

What to watch: The prompt focuses on explicitly altered tables but misses views, materialized views, triggers, stored procedures, or application code that depend on the changed schema. This creates a false sense of security when downstream objects break silently. Guardrail: Include a dependency graph or pg_depend/sys.sql_expression_dependencies output in the prompt context. Add a mandatory step requiring the model to list dependent objects before recommending tests.

03

Overlooking Data Type Coercion Risks

What to watch: The model correctly identifies the need for integrity checks but fails to account for implicit coercion, truncation, or precision loss during type changes (e.g., FLOAT to INTEGER, VARCHAR(255) to VARCHAR(100)). Existing data may pass a basic count check but silently corrupt. Guardrail: Add a specific constraint in the prompt to flag any type narrowing or coercion and generate boundary-value tests for the full range of existing production data, not just sample rows.

04

Rollback Test Omission

What to watch: The model generates a thorough forward-migration test plan but neglects rollback verification entirely. In production, a failed migration with an untested rollback path causes extended downtime. Guardrail: Explicitly require a symmetric rollback test section in the output schema. The prompt must ask for tests that verify the schema returns to its exact pre-migration state, including index and constraint restoration.

05

Performance Test Blindness

What to watch: The model treats the migration as a purely logical operation and ignores performance regression risks, such as new indexes slowing writes, rewritten queries generating suboptimal plans, or lock escalation during the migration itself. Guardrail: Include a performance context block with table cardinalities and current query patterns. Instruct the model to recommend EXPLAIN plan comparisons and lock-timeout tests as part of the test selection.

06

Constraint Validation Ordering Errors

What to watch: The model suggests validating foreign key constraints before the referenced primary key data is verified, or checks NOT NULL constraints after data backfill. This leads to false-positive test failures or missed violations. Guardrail: Embed a dependency-ordered validation sequence in the prompt instructions. Require the output to list tests in execution order, with explicit preconditions stating which prior tests must pass first.

IMPLEMENTATION TABLE

Evaluation Rubric

Criteria for evaluating the quality of a database schema migration test selection before shipping it to a test runner or release gate. Each row defines a pass standard, a failure signal, and a concrete test method.

CriterionPass StandardFailure SignalTest Method

Migration Type Detection

Correctly identifies the migration type (e.g., additive, destructive, refactor, backfill) from the DDL diff

Misclassifies a destructive change as additive or ignores data backfill operations

Run prompt against 10 labeled DDL diffs; require >= 90% classification accuracy

Referential Integrity Coverage

Every foreign key relationship modified by the migration has at least one corresponding test case

A modified FK constraint has zero associated test cases in the output

Parse output for FK references in the DDL; cross-reference with generated test list; require 100% match

Backward Compatibility Check

Output includes explicit test cases for old-client compatibility when schema change is not purely additive

No backward-compat tests generated for a column rename or type change

Inject a column-rename migration; assert output contains at least one test with 'old client' or 'backward compat' label

Rollback Test Inclusion

Every migration step with a defined rollback has a corresponding rollback verification test

A migration with a DROP COLUMN has no rollback test for data restoration or schema reversal

Parse migration for DROP, RENAME, or ALTER; assert each has a paired rollback test in the output

Performance Regression Signal

Output flags potential performance risks (e.g., index rebuild, large table scan) and suggests a performance test

A migration adding a non-covering index to a 100M-row table generates no performance test recommendation

Provide a migration with a documented performance risk; assert output contains a performance test or explicit risk note

Constraint Validation Completeness

All CHECK, UNIQUE, and NOT NULL constraints in the migration have a boundary and null-input test case

A new CHECK constraint on a numeric range has no boundary test (min-1, max+1)

Parse DDL for constraint definitions; assert each constraint type has at least one boundary test and one null test

Data Integrity Test Specificity

Data migration steps (e.g., UPDATE, backfill) have tests verifying row counts, checksums, or sample comparisons pre/post migration

A backfill UPDATE affecting 50% of rows has only a generic 'data is correct' test without a verification method

Provide a migration with a data backfill step; assert output includes a row-count or checksum verification test

Selection Rationale Auditability

Each recommended test includes a one-line rationale linking it to a specific migration change or risk

Test list contains entries with no rationale or a rationale that does not reference the migration DDL

Sample 5 random test entries from output; assert each rationale string contains a DDL object name or migration line reference

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Start with the base prompt and a single migration script diff as [MIGRATION_DIFF]. Replace the structured output schema with a simpler checklist format. Skip the rollback and performance regression sections initially. Use a lightweight model (e.g., GPT-4o-mini, Claude Haiku) to iterate quickly.

Prompt modification

Remove the [OUTPUT_SCHEMA] placeholder and replace with:

code
Return a markdown checklist with three sections:
- Data Integrity Tests
- Constraint Validation Tests
- Backward Compatibility Tests

Watch for

  • Missing referential integrity checks on foreign key changes
  • Overlooking NOT NULL constraint additions that break existing data
  • No distinction between DDL and DML migration risks
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.