Python

Verified against ChatGPT · 2026-08-09

Design a normalized table schema for a new feature without breaking the tables already in production

Produces a normalized schema for a new feature plus a phased migration plan against your existing tables, so the design doesn't just look right on a whiteboard but actually ships without a destructive rewrite.

ChatGPT5 fillable variables

The prompt

Ready to copy — highlighted parts are example details you can swap.

You are a database architect designing the schema for a new feature that has to coexist with tables already live in production — this is not a greenfield design exercise, so every decision has to account for what already exists and what would break if handled carelessly.

FEATURE BEING ADDED
Let a customer save multiple shipping addresses and pick a default one at checkout.

EXISTING RELEVANT TABLES
customers(id, name, email), orders(id, customer_id, shipping_address_text) — address is currently a single free-text column on orders.

DATABASE ENGINE AND VERSION
PostgreSQL 15, running on RDS

EXPECTED SCALE AND ACCESS PATTERN
orders table has ~40M rows and is read on every checkout page load; write volume is ~50k orders/day.

CONSTRAINTS THAT CANNOT CHANGE
No downtime allowed during business hours (9am-9pm ET); a nightly BI job queries orders.shipping_address_text directly and can't break.

PHASE 1 — SCHEMA DESIGN
Design the new tables and any columns added to existing tables, normalized to at least 3NF unless the stated access pattern gives a specific, named reason to denormalize (a read path that would otherwise require a join across more than three tables on every request, for example) — and if you do denormalize anything, say exactly which normal-form rule you're breaking and why the access pattern justifies it, rather than denormalizing by default and calling it a performance decision after the fact. Every foreign key needs an explicit ON DELETE behavior (CASCADE, RESTRICT, SET NULL) chosen deliberately, not left at the engine default, because the default silently varies by engine and picking it by omission is how orphaned rows or unintended cascading deletes happen later.

PHASE 2 — MIGRATION PLAN
Given the existing tables listed above already have production data and traffic, write the migration as an ordered list of individually-reversible steps, each one safe to run without locking the affected table for longer than a few seconds — call out specifically any step that would require a full table rewrite or an ACCESS EXCLUSIVE lock at the stated scale, and propose the safer alternative (adding a nullable column first and backfilling in batches, for example, rather than adding a NOT NULL column with a default directly). Do not propose a single big migration script that does everything in one transaction if any individual step in it is risky at the stated scale.

PHASE 3 — WHAT COULD GO WRONG
Name the one existing table most likely to have data that violates a new constraint you're adding (a NOT NULL, a new foreign key, a new UNIQUE constraint) and specify how you'd find out before the migration runs, not after it fails partway through.

OUTPUT FORMAT
1. Schema as DDL (CREATE TABLE / ALTER TABLE statements).
2. One-paragraph explanation of any deliberate denormalization.
3. The ordered, reversible migration step list.
4. The pre-migration data-validation query for the risk named in Phase 3.

Customize

Optional — swap in your own details for the highlighted parts above.

Why this works

Asking for a migration plan as ordered, individually-reversible steps rather than a single design deliverable forces the model out of academic schema design mode, where a textbook-correct 3NF layout is treated as the whole answer, and into the actual constraint that matters in a live system: an ALTER TABLE that looks trivial in DDL can take an ACCESS EXCLUSIVE lock and block every other query against that table for the duration of a full rewrite, which for a 40-million-row table is not a hypothetical, it's an outage. Requiring an explicit ON DELETE behavior on every foreign key instead of accepting the engine default closes a specific failure mode where a model asked for "a schema" writes syntactically correct DDL that compiles fine and then produces silent data-integrity drift in production months later, because the default cascade behavior was never a deliberate choice anyone reviewed. The Phase 3 requirement — naming the one existing table most likely to violate a new constraint — matters because the standard failure pattern with adding NOT NULL or UNIQUE to an already-populated table isn't a design flaw, it's a migration that runs fine in a schema-design review and then fails at 2am partway through backfilling real production rows that don't satisfy the new rule, which is exactly the class of failure a pre-migration validation query catches before the migration is ever run rather than after it's half-applied. Requiring a stated reason for any denormalization, rather than letting the model default to whichever shape looks cleaner, keeps a genuine access-pattern-driven trade-off distinguishable from an unexamined shortcut in the eventual code review.

What you get back

CREATE TABLE addresses (id BIGSERIAL PRIMARY KEY, customer_id BIGINT NOT NULL REFERENCES customers(id) ON DELETE CASCADE, line1 TEXT NOT NULL, city TEXT NOT NULL, is_default BOOLEAN NOT NULL DEFAULT false); Migration step 1: add addresses table (no lock impact, new table). Step 2: add nullable orders.address_id column via ALTER TABLE ... ADD COLUMN (fast, metadata-only in PG11+). Step 3: backfill address_id in batches of 5,000 rows to avoid long-running transactions. Step 4: only after backfill is verified complete, add the NOT NULL constraint using NOT VALID + VALIDATE CONSTRAINT to avoid a full table scan lock.

Verified against

ChatGPT GPT-5.1 · 2026-08-09

Changelog

  • 2026-08-09 Initial publish, verified against ChatGPT GPT-5.1.

Need this built into your business?

If a prompt isn't enough — custom software, built and maintained for you — that's Scult's day job.

EXPLORE CUSTOM SOFTWARE
All Python prompts

Check your AI visibility

One URL in, a 0–100 score and the exact fixes out.

RUN THE CHECK

Browse all the tools

15 tools across six categories
13 of them never send your data anywhere

Free · No signup · No trial clock

SEE THE DIRECTORY