Skip to content

Database Migrations

Guide to managing database migrations in Lager Guru.

Overview

Migrations are used to manage database schema changes in a version-controlled way.

Migration Files

Migrations are located in supabase/migrations/ directory.

Creating Migrations

Using Supabase CLI

bash
supabase migration new migration_name

Manual Creation

Create a new file in supabase/migrations/ with timestamp prefix:

YYYYMMDDHHMMSS_migration_name.sql

Migration Structure

sql
-- Migration: Add new column to shipments
-- Created: 2025-12-02

ALTER TABLE shipments
ADD COLUMN new_field TEXT;

CREATE INDEX idx_shipments_new_field ON shipments(new_field);

Running Migrations

Local Development

bash
supabase db reset

Production

Migrations are applied automatically via CI/CD or manually:

bash
supabase db push

Best Practices

  • One logical change per migration
  • Include rollback instructions
  • Test migrations locally first
  • Document breaking changes
  • Use transactions when possible

Rollback

Manual Rollback

Create a new migration to reverse changes:

sql
-- Rollback: Remove column from shipments
ALTER TABLE shipments
DROP COLUMN new_field;

Migration Checklist

  • [ ] Test migration locally
  • [ ] Verify RLS policies
  • [ ] Check indexes
  • [ ] Test rollback
  • [ ] Document changes
  • [ ] Update schema documentation

Next Steps

Released under Commercial License