Enhanced type safety for the booking_requests.status field by replacing generic string type with a specific TypeScript enum that enforces valid database values.
booking_request_status_enum: "sent" | "viewed" | "accepted" | "rejected" | "expired"This enum was added to the Database["public"]["Enums"] section to match the database constraint:
- sent: Initial state when request is sent to mover
- viewed: Mover has viewed the request
- accepted: Mover has accepted the booking
- rejected: Mover has declined the booking
- expired: Request expired without response
Before:
status: stringAfter:
status: Database["public"]["Enums"]["booking_request_status_enum"]Before:
status?: stringAfter:
status?: Database["public"]["Enums"]["booking_request_status_enum"]Before:
status?: stringAfter:
status?: Database["public"]["Enums"]["booking_request_status_enum"]TypeScript will now catch invalid status values at compile time:
// ✅ Valid - will compile
await supabase
.from('booking_requests')
.update({ status: 'accepted' })
// ❌ Invalid - TypeScript error
await supabase
.from('booking_requests')
.update({ status: 'invalid_status' }) // Error: Type '"invalid_status"' is not assignableIDEs will provide autocomplete suggestions for valid status values:
- sent
- viewed
- accepted
- rejected
- expired
Type definitions now match the database constraints defined in migration:
-- From: supabase/migrations/20251008_part2_marketplace_schema.sql
status TEXT NOT NULL DEFAULT 'sent', -- 'sent', 'viewed', 'accepted', 'rejected', 'expired'When refactoring code that uses booking_requests.status, TypeScript will highlight all usages that need updating if enum values change.
const { data, error } = await supabase
.from('booking_requests')
.insert({
booking_id: '123',
mover_id: '456',
status: 'sent', // ✅ Type-safe
expires_at: new Date().toISOString()
});const { data, error } = await supabase
.from('booking_requests')
.update({
status: 'accepted', // ✅ Autocomplete available
responded_at: new Date().toISOString()
})
.eq('id', requestId);const { data, error } = await supabase
.from('booking_requests')
.select('*')
.eq('status', 'sent') // ✅ Type-safe
.lt('expires_at', new Date().toISOString());type BookingRequestStatus = Database["public"]["Enums"]["booking_request_status_enum"];
function isValidStatus(status: string): status is BookingRequestStatus {
return ['sent', 'viewed', 'accepted', 'rejected', 'expired'].includes(status);
}To regenerate type definitions after database schema changes:
# Using Supabase CLI
supabase gen types typescript --project-id YOUR_PROJECT_ID > src/integrations/supabase/types.ts
# Or with local development
supabase gen types typescript --local > src/integrations/supabase/types.tsImportant: After regenerating, manually verify that enum types are correctly referenced in Row/Insert/Update types.
- Database Migration:
supabase/migrations/20251008_part2_marketplace_schema.sql - Type Definitions:
src/integrations/supabase/types.ts - Usage Examples:
src/pages/MoverDashboard.tsx(mover responds to requests)src/services/api.ts(booking request API functions)
The types.ts file may show some TypeScript errors related to the Database structure. These are pre-existing issues with the generated types and do not affect the functionality of the enum types added in this enhancement.
Consider applying the same pattern to other string fields that have constrained values:
- ✅
booking_requests.status(completed) - ⏳ Other potential candidates in the codebase
After making these changes, test the following scenarios:
- Creating new booking requests with valid status values
- Updating booking request status
- Filtering by status in queries
- Verify IDE autocomplete works correctly
- Confirm TypeScript catches invalid status values at compile time