StoicBuilder

HandbookII the ForumSchema and migrations

IIthe Forum, The shape of an app

Schema and migrations

1 min readUpdated 28 November

In plain words

The schema is the shape of your database, its tables, columns and rules, and a migration is a saved script that changes that shape one step at a time.

Where you see it

The supabase/migrations folder in your project, full of files like 20261204103000_add_delivery_fee.sql. Each one is a single change to the database, kept in order, so your laptop, staging and production end up identical.

supabase/migrations/20261204103000_add_delivery_fee.sqldatabase
alter table orders add column delivery_fee numeric(10, 2) not null default 0;
One small, named change. Run it on every copy of the database and they all match.

What goes wrong

  1. Deploying code before its migration runs

    The new code asks for delivery_fee, the live database doesn't have it yet, and every order fails.

    ERROR: column "delivery_fee" does not exist
  2. Changing production by hand

    Adding a column in the Supabase Table Editor fixes production but leaves no migration behind. The next fresh setup, or a teammate's laptop, won't have it.

  3. A rename that quietly drops data

    Some generated migrations rename a column by dropping it and adding a new one, which deletes every value in it. Read any migration containing drop before it runs.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Make this database change as a new migration file, not by editing the database directly or changing an old migration. Before running it, tell me in plain words what it changes and whether it can delete any existing data.

Quick check

Sign in to earn +10 XP for it

The app works locally, but after deploy every order fails with "column delivery_fee does not exist". Why?

Got a prompt that touches schema and migrations?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.