Database
Schema & Migration

Schemas & Migrations

This document outlines the process of managing database schemas and migrations using the Supabase CLI. Schemas define the structure of your database, while migrations allow you to version control and manage changes to your database schema over time.

💡

Check out the official Supabase CLI documentation (opens in a new tab) on migrations, schema management, and seeding.

Supabase CLI

We use the Supabase CLI to manage our database schemas and migrations. The CLI provides a set of commands to create, apply, and manage database migrations.

Project Structure

      • 20230801120000_initial_schema.sql - Example Schema Definition
    • seed.sql - Database Seed Data
  • Running Example Migrations and Seed

    To run the example migrations and seed data:

    supabase db reset

    This command resets your database, applies all migrations, and runs the seed.sql file.

    Key Commands

    • Create a new migration:
    supabase migration new <migration_name>
    • Apply migrations:
    supabase db push
    • Reset database and reapply all migrations:
    supabase db reset
    • Check migration status:
    supabase db status

    Local vs. Linked Project Operations

    By default, commands operate on your local development database. For linked remote projects, use the --linked flag:

    supabase db push --linked
    supabase db reset --linked
    supabase db status --linked

    Remember to exercise caution when operating on remote databases, especially in production environments.