Fix: DB Schema Column Name Mismatches
Branch: fix/db-schema-column-names
Date: 2026-03-18
Impact: 4 runtime PostgrestException errors crashing crew/squad features
Root Cause
The Dart code assumed column names that didn’t match the actual Supabase schema. These were discovered via app_issues error reports.
Error 1 & 2 — crew_members.created_at / squad_members.created_at do not exist
Actual column: joined_at (both tables only have joined_at, not created_at)
A prior fix incorrectly changed .order('joined_at') → .order('created_at') in getMyCrew() and getMySquad(). Both crew_members and squad_members only have joined_at.
Fix: Reverted back to .order('joined_at', ascending: false) in both services.
Error 3 — squads.expires_at does not exist
Actual column: valid_until
Three places used expires_at instead of the real column name:
SquadService.getActiveSquads()—.gt('expires_at', now)in the query filterSquadService.createSquad()—'expires_at': ...in the insert payloadSquad.fromJson()—json['expires_at']when deserializing from DB
Fix: All three changed to valid_until. The Dart model field (expiresAt) stays the same — only the JSON key changes.
Error 4 — crew_must_have_anchor check constraint violation
Constraint: CHECK ((event_id IS NOT NULL) OR (venue_id IS NOT NULL) OR (area_name IS NOT NULL))
Every crew must be anchored to an event, venue, or named area. createCrew() was only inserting current_location (a freeform string), but the constraint requires at least one of the three typed anchor columns.
Fix: createCrew() now also inserts area_name: currentLocation alongside current_location, satisfying the constraint when a location is provided.
Schema Reference
| Table | Relevant columns |
|---|---|
crew_members | crew_id, user_id, role, joined_at |
squad_members | id, squad_id, user_id, role, joined_at |
squads | id, creator_id, title, vibe_tag, max_size, is_active, valid_until, created_at |
crews | id, creator_id, title, vibe_tag, event_id, venue_id, area_name, is_active, valid_until, created_at |
Files Changed
| File | Change |
|---|---|
lib/features/social/services/crew_service.dart | joined_at order restored; area_name added to insert |
lib/features/social/services/squad_service.dart | joined_at order restored; expires_at → valid_until in query and insert |
lib/shared/models/squad_model.dart | fromJson/toJson use valid_until key |