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 filter
  • SquadService.createSquad()'expires_at': ... in the insert payload
  • Squad.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

TableRelevant columns
crew_memberscrew_id, user_id, role, joined_at
squad_membersid, squad_id, user_id, role, joined_at
squadsid, creator_id, title, vibe_tag, max_size, is_active, valid_until, created_at
crewsid, creator_id, title, vibe_tag, event_id, venue_id, area_name, is_active, valid_until, created_at

Files Changed

FileChange
lib/features/social/services/crew_service.dartjoined_at order restored; area_name added to insert
lib/features/social/services/squad_service.dartjoined_at order restored; expires_atvalid_until in query and insert
lib/shared/models/squad_model.dartfromJson/toJson use valid_until key