Skip to Content
DocsDeploymentDatabase Migrations

Database Migrations

Marqov uses Supabase (hosted PostgreSQL) for its database. Migrations are SQL files applied via the Supabase SQL Editor.


Migration File Location

platform/supabase/migrations/

Naming Convention

NNN_description.sql
  • NNN: Three-digit zero-padded sequence number (e.g., 001, 059)
  • description: Snake-case description of the change

Examples:

  • 001_initial_schema.sql
  • 047_team_suspension.sql
  • 054_inline_code_on_job_runs.sql

Current Schema Version

059 (059_add_quantum_brilliance_backends.sql)


How to Apply Migrations

Migrations are applied manually via the Supabase SQL Editor since the platform uses a remote Supabase instance (not local).

  1. Open the Supabase Dashboard: https://supabase.com/dashboard
  2. Navigate to your project
  3. Open SQL Editor
  4. Copy the contents of the migration file
  5. Run the SQL
  6. Verify the migration applied successfully

There is no automated migration runner. Each migration must be applied in sequence.


Writing a New Migration

  1. Determine the next sequence number by checking the last file in platform/supabase/migrations/.
  2. Create a new file: NNN_description.sql
  3. Write idempotent SQL where possible (use IF NOT EXISTS, IF EXISTS, OR REPLACE).
  4. Test in a development environment before applying to production.
  5. Commit the migration file to version control.

Best Practices

  • Use ALTER TABLE ... ADD COLUMN IF NOT EXISTS for column additions.
  • Use CREATE OR REPLACE for functions and views.
  • When adding new columns to a view, you must DROP and CREATE it (cannot insert columns in the middle).
  • Wrap multi-statement migrations in BEGIN; ... COMMIT; for atomicity.
  • Add COMMENT ON COLUMN for new columns to document their purpose.
  • Use NOT VALID on constraints to skip checking existing rows.

Important Migrations

#DescriptionTables Affected
001Initial schemateams, team_members, scripts, job_runs, job_results, webhook_endpoints, webhook_deliveries
002Team invitationsteam_invitations
005RLS fix with security definerRLS policies
006Backends tablebackends (seeded with 11 devices)
010Benchmark suitesbenchmark_suites, benchmark_suite_jobs
012Capsulescapsules, capsule_artifacts, capsule_task_executions
014Invitation codesinvitation_codes
042Providers tableproviders
045Cost trackingcost tracking columns and RPC functions
047Team suspensionteams.suspended_at, team_stats_summary view
048Security hardeningRLS policy updates
050Simulation eventssimulation_events
051Template migrationscripts.framework, job_runs.execution_mode, slug+framework unique constraint
052-053Seed scriptsscripts (Bell State variants, VQE, QAOA)
054Inline codejob_runs.inline_code, job_runs.framework, scripts INSERT policy
055Script requirementsscripts.requirements fixes
056Marqov simulatorbackends (marqov-sim)
058Workflow metadatajob_runs.workflow_metadata
059Quantum Brilliancebackends (qb-sim-*)

Troubleshooting

db:types command warning: The Supabase CLI command supabase db:types redirects output to database.types.ts. If the command fails (e.g., lacking access), it empties the file. Always git restore platform/src/lib/database.types.ts if the command fails.

Column type mismatches: If generated types do not include recently added columns (e.g., framework, inline_code), use as any casts in TypeScript until types are regenerated.

View recreation: CREATE OR REPLACE VIEW cannot change the column order or insert new columns in the middle. New columns must be appended at the end, or the view must be dropped and recreated.

Last updated on