Database Migration Safety Policy
This policy defines how Brightweb evolves client databases safely while moving from BeGreen-first history to Brightweb-owned module migrations.
Core rule
Use forward migrations only.
Do not rewrite, reorder, or replay already-applied production migration history casually.
What this means
Allowed
- add new migrations on top of the current real schema
- create new shared Brightweb migrations for future work
- create client-only forward migrations when truly needed
- refactor ownership in Brightweb docs and folders without changing the live database
Not allowed
- editing historical BeGreen SQL files that have already been applied to production
- moving old migration files into a new order and replaying them as if history changed
- assuming a fresh client can safely replay BeGreen’s entire flat history without review
- mixing one-off client behavior into shared module migrations
Current state
BeGreen is the first real client and already has a flat migration history in:
/Users/leoribeiro/Documents/02_Projects/BeGreen/2025-12_FullIdentity/03_Work/Website/Development/be-green/supabase/migrations
Brightweb is now the source of truth for future shared database work in:
supabase/modules/coresupabase/modules/adminsupabase/modules/crmsupabase/modules/projectssupabase/clients/<slug>
Safety model by client type
Existing client: BeGreen
- treat the current database schema as authoritative
- do not attempt to reconstruct it by replaying newly reorganized Brightweb folders
- apply only forward migrations from this point onward
New client
- provision from Brightweb-owned module structure
- apply
core - apply enabled module migrations in dependency order
- apply client-only migrations only if needed
Adoption rule for shared module work
When a new shared schema change is needed:
- classify the change by owner:
core,admin,crm,projects, orclient - create a new forward migration in Brightweb
- apply it only to clients that need that module
- never “back-edit” old BeGreen history to pretend the structure existed earlier
Release gate before applying SQL
Before any migration is applied to a real client database:
- confirm target client and enabled modules
- confirm the migration owner bucket is correct
- confirm the change is forward-only
- confirm whether it is shared or client-only
- confirm rollback expectations
- confirm affected tables, functions, triggers, and policies
Special rule for RLS and helper functions
Changes to:
- RLS policies
- helper functions used in policies
- auth/profile sync functions
- admin role mutation functions
must be treated as high risk and reviewed as shared platform changes, not casual client tweaks.
Practical summary
- BeGreen production history stays intact
- Brightweb owns future shared migrations
- BeGreen receives new schema changes as forward migrations only
- new clients should start from Brightweb module-based schema, not from BeGreen’s historical flat folder
Repo source
docs/architecture/database-migration-safety-policy.mdThis page is rendered directly from the root docs folder. Edit the markdown there, not inside the app.