Database Migrations
Database Migrations
Section titled “Database Migrations”Applying Migrations
Section titled “Applying Migrations”This project stores migrations in the archive/ subdirectory for organizational purposes.
Latest Migration: Seed Functions (2025-11-22)
Section titled “Latest Migration: Seed Functions (2025-11-22)”File: 20251122000000_add_seed_functions.sql
This migration adds essential seed functions for demo data:
seed_default_scrap_reasons()- Seeds standard scrap/rejection codesseed_demo_operators()- Creates 4 demo operator profilesseed_demo_resources()- Creates 9 sample resources (molds, tooling, fixtures, materials)get_part_routing()- Returns routing sequence for parts (used by QRM metrics)
How to Apply
Section titled “How to Apply”Option 1: Supabase Dashboard (Recommended)
Section titled “Option 1: Supabase Dashboard (Recommended)”- Go to your Supabase project dashboard
- Navigate to SQL Editor
- Copy the contents of
20251122000000_add_seed_functions.sql - Paste and run the SQL
Option 2: Supabase CLI
Section titled “Option 2: Supabase CLI”# If you have the Supabase CLI installedsupabase db push
# Or apply specific migrationcat supabase/migrations/20251122000000_add_seed_functions.sql | supabase db executeUsing the Seed Functions
Section titled “Using the Seed Functions”After applying the migration, you can seed your tenant with demo data:
-- Seed scrap reasonsSELECT * FROM seed_default_scrap_reasons('your-tenant-id');
-- Seed demo operatorsSELECT * FROM seed_demo_operators('your-tenant-id');
-- Seed demo resourcesSELECT * FROM seed_demo_resources('your-tenant-id');Note: These functions are also called automatically when you import sample data through the onboarding wizard in the UI.
Migration History
Section titled “Migration History”All applied migrations are stored in archive/ for reference. The migrations are numbered chronologically:
- Format:
YYYYMMDDHHMMSS_description.sql - Example:
20251122000000_add_seed_functions.sql