Skip to Content
Self-HostingDatabase Migrations

Database Migrations

All database schema changes are tracked as SQL migration files in supabase/migrations/. Each file is timestamped and applied in order.

Applying Migrations

Local development

These commands require a linked Supabase project (supabase link --project-ref <ref>) or a local Supabase instance started with supabase start:

# Apply all pending migrations supabase db push # Reset and re-apply all migrations (destructive — local only) supabase db reset --no-seed

Production

Migrations run automatically on container startup via the docker-entrypoint.sh script using scripts/run-migrations.mjs. This script:

  1. Connects to the configured Supabase instance
  2. Checks which migrations have already been applied
  3. Applies any pending migrations in order
  4. Logs the result

Migrations are idempotent — running against an up-to-date database is a no-op.

Manual application

You can also apply migrations manually via the Supabase SQL editor or psql:

psql $DATABASE_URL -f supabase/migrations/20251027000001_data_as_a_service_schema.sql

Migration Files

Files are named YYYYMMDDHHMMSS_description.sql and applied in lexicographic order. Examples from the current set:

FileDescription
20251027000001_data_as_a_service_schema.sqlCore tables: daas_users, daas_roles, etc.
20251030000001_enable_row_level_security.sqlRow-Level Security policies
20251030000003_create_audit_logging.sqlAudit triggers on system tables
20251028000001_add_get_tables_function.sqlPostgreSQL helper functions
20260212000001_rename_prefix_to_daas.sqlTable renames and schema migration

Creating a New Migration

supabase migration new my_migration_name # Creates: supabase/migrations/<timestamp>_my_migration_name.sql

Write your SQL in the generated file, then apply it (requires a linked project or local instance):

supabase db push
Last updated on