Vibe Coder · Unit 12: Login and Data With Supabase · Lesson 6 of 6

Migrations and types

Engineers: keep the database schema in version control with migrations, and generate types so the app and database cannot drift apart.

Read the short notes and pictures.Do everything inside a blue frame.

Schema as code

Migrations make database changes reviewable and repeatable. With the Supabase CLI you develop against a local database, commit each change as a SQL file, and apply the same files to production. Generated TypeScript types keep application code in step with the schema.

A 3D scene of coloured blocks and cards. One change per file: supabase/migrations/,   0003_add_invoice_status.sql.
A migration file describes one change.

Practices

One change per migration

Small and reviewable.

RLS in migrations

Policies are schema too.

Never edit an applied migration

Add a new one.

Regenerate types on change

And commit them.

A 3D scene of coloured blocks and cards. The flow: write, review, apply locally, apply to production.
Write, review, apply locally, then to production.

With an agent

  1. Have it write the migration

    Not run ad hoc SQL.

  2. Read the SQL

    Especially drops and policy changes.

  3. Apply locally and test

    Including the two-account RLS test.

  4. Apply to production in CI

    Not from a laptop.

ActivityBuild stepSign-in and saved data

Put your schema under version control

Move your schema and RLS policies into migrations, generate types, and add a CI step that fails if types are out of date. Add a test that proves one user cannot read another’s rows.

Done when

Sign-in and saved data are complete and under version control.

Keep these

  • Migrations make schema changes reviewable.
  • Generate types from the schema.
  • Test RLS automatically.