Sync Test Factories and Fixtures with Database Migrations

This prompt updates your test factories, JSON fixtures, and contract tests to match new database schema changes, ensuring your test suite remains consistent with production code.

Agent prompt for ChatGPT and Claude

Prompt

Prompt
Act as a Senior Backend Engineer. Your task is to update the test suite to reflect recent database schema changes. Please ask the following 3 questions first and wait for my response: 1. Paste the SQL migration file content. 2. List the file paths of the factories, JSON fixtures, and contract test files that need updating. 3. Describe the specific changes in the migration, such as added columns, renamed fields, or dropped constraints. Once I provide these, perform the following: 1. Update the factory definitions to include the new fields with appropriate default values. 2. Add or update the mock JSON fixtures to match the new schema structure. 3. Update the contract tests to validate the new fields or handle removed ones. 4. Write only the modified code blocks with the file path header above each block. Output format: For each file, provide a header with the file path followed by a code block containing the updated logic. Ensure all changes maintain existing data types and relationships. This is not professional software engineering advice; verify all changes in a staging environment before deployment.

Example output

Test artifacts updated for user_preferencesThree files changed to match the new users column
  1. Update user factoryuser.factory.jsDefault user gets a user_preferences object
  2. Update JSON fixturesusers.jsonAlice gets theme dark, notifications false
  3. Update contract testuser_contract.test.jsChecks theme is a string, notifications a boolean

Example for: adding a user_preferences column to the users table and updating associated test artifacts.

/tests/factories/user.factory.js
export const userFactory = (overrides = {}) => ({
  id: 1,
  username: 'test_user',
  email: 'test@example.com',
  user_preferences: { theme: 'light', notifications: true },
  ...overrides
});
/tests/fixtures/users.json
[
  {
    "id": 1,
    "username": "alice",
    "email": "alice@example.com",
    "user_preferences": { "theme": "dark", "notifications": false }
  }
]
/tests/api/user_contract.test.js
describe('User Schema Contract', () => {
  test('response includes user_preferences object', async () => {
    const response = await fetch('/api/user/1');
    const data = await response.json();
    expect(data).toHaveProperty('user_preferences');
    expect(data.user_preferences).toMatchObject({
      theme: expect.any(String),
      notifications: expect.any(Boolean)
    });
  });
});
Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Forces structured inputs to prevent hallucination of schema details.
  • Ensures cross-file consistency by requiring all affected paths upfront.
  • Includes a safety warning to verify changes in staging.

Use this in Cursor, ChatGPT, or Claude when a database migration breaks your test suite. Have your SQL migration file, factory definitions, and test files ready to paste.

Common edits

  • Adjust the test framework syntax if using something other than Jest.
  • Add a rule to specifically handle migration rollback logic if needed.

Reuse it: Use in a workflowAdapt in the builder

Prompt details

By
Prompts-GPT editors
Published
How prompts are written and checked

Did this prompt work?

More in Cursor

Automated Dead Code Cleanup Plan for Codex Repositories

Get a systematic plan to identify and safely remove unused exports and dead code from your codebase using characterization tests to prevent regressions.

Agent OrchestrationClaude

Design Mock Tool Fixtures for Agent Trajectory Testing

Generate deterministic mock tool responses to test agent decision trees, edge-case failures, and schema-breaking payloads without live API usage or costs.

Coding

Port a Function or Module to Another Language With Tests Proving Same Behavior

Lists the source code's behaviors and edge cases, writes tests in the target language first, ports the code idiomatically, and gives a table of library mappings and semantics that differ.

Design a Benchmark Harness for Claude Code Agent Accuracy

Create a structured testing framework to evaluate coding agent performance on pull requests using deterministic ground-truth verification.

Cursor Characterization-Test-First Refactor of a Legacy Module

Has Cursor lock in current behavior with characterization tests before restructuring a legacy module in small steps, so you can decide whether the refactor preserved behavior and is safe to merge.

Create Selective Pre-Commit Hooks for Claude Code

This prompt generates a bash script that triggers specific tests and typechecks only for packages modified in your current git branch.