Source:
ocean/docs/SCHEMA_DRIFT_ANALYSIS.md| ✏️ Edit on GitHub
Schema Drift Analysis - Organizations Table
Summary
Based on my analysis of the codebase, I've identified several schema drift issues between the database schema, GraphQL schema, Edge Functions, and frontend code expectations for the organizations table.
Current Database Schema (Actual)
The organizations table currently has these columns (confirmed via psql query):
trial_end(NOTtrial_ends_at)subscription_quantity(NOTseats_includedorseats_used)subscription_status(simplified status)stripe_subscription_status(detailed Stripe status)
Historical Issues Found
1. Column Name Mismatches
Migration 20250828163000_fix_trial_column_name.sql fixed these issues:
- Wrong:
trial_ends_at→ Correct:trial_end - Wrong:
seats_included/seats_used→ Correct:subscription_quantity
2. Code References to Wrong Column Names
Found in older migrations that were using incorrect column names:
20250819000002_fix_schema_drift_comprehensive.sql- referencestrial_ends_at,seats_included,seats_used20250826000001_fix_handle_new_user_error_column.sql- same incorrect references
Current State Analysis
✅ Correctly Aligned Components
- Database Schema: Uses correct column names (
trial_end,subscription_quantity) - GraphQL Resolvers: Query correct columns in base.ts
- Edge Functions:
handle-stripe-webhookusessubscription_quantity- GraphQL mutations use
subscription_quantity
- Billing Views: Reference
trial_endcorrectly
⚠️ Potential Issues
-
TypeScript Types (
src/types/supabase.ts):- Missing many columns that exist in the actual database
- Only includes:
subscription_statusbut notstripe_subscription_status - Missing:
trial_end,subscription_quantity,plan,owner_id, etc.
-
Frontend Code:
- No direct references to the problematic column names found
- Uses GraphQL API which abstracts the database columns
🔍 Key Findings
-
Two Status Fields: The database has both:
subscription_status: Simplified status ('free', 'trial', 'active', 'canceled', 'past_due')stripe_subscription_status: Detailed Stripe status ('trialing', 'active', 'canceled', etc.)
-
Migration History: The schema was corrected in migration
20250828163000, but older migrations still contain references to the wrong column names. -
GraphQL Abstraction: The GraphQL layer successfully abstracts these database details from the frontend, preventing direct exposure of schema issues.
Additional Schema Drift Issues
Missing Tables in TypeScript Types
The TypeScript types file (src/types/supabase.ts) is severely out of date:
- Database has: 26 tables
- TypeScript defines: Only 3 tables (organizations, organization_members, provisioning_events)
Missing critical tables include:
stripe_productsstripe_pricesstripe_price_planssubscription_itemspayment_methodsprofiles- And ~17 other tables
Recommendations
-
Regenerate TypeScript Types: The
src/types/supabase.tsfile needs to be completely regenerated to include:- All 26 database tables
- All columns for the organizations table
- Proper type definitions for JSONB columns
-
Use Supabase CLI: Run
supabase gen types typescriptto regenerate accurate types from the current schema. -
Clean Up Old Migrations: While not affecting runtime, the older migrations with incorrect column names could cause confusion.
-
Consistent Status Usage: Clarify when to use
subscription_statusvsstripe_subscription_status. -
No Frontend Changes Needed: The frontend correctly uses the GraphQL API and doesn't directly reference database columns.
Verification Commands
To verify the current state:
# Check actual database columns
psql $DATABASE_URL -c "SELECT column_name FROM information_schema.columns WHERE table_name = 'organizations' ORDER BY ordinal_position;"
# Search for any remaining references to old column names
grep -r "seats_included\|seats_used\|trial_ends_at" --include="*.ts" --include="*.tsx" --exclude-dir=node_modules --exclude-dir=migrations_backup
# Verify GraphQL schema expectations
cat supabase/functions/graphql-v2/schema.ts | grep -A20 "type Organization"
Conclusion
The schema drift has been largely resolved at the database and API levels. The main remaining task is to update the TypeScript type definitions to accurately reflect the current database schema.