File tree Expand file tree Collapse file tree
packages/server/src/rooms Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -608,10 +608,12 @@ export class GameRoom implements DurableObject {
608608 } ) ;
609609 }
610610 const db = getDb ( this . env . DB ) ;
611+ // games row must land before any FK-dependent insert (game_participants,
612+ // daily_attempts both reference games.id). D1 dispatches concurrent
613+ // prepared statements independently, so Promise.all-ing all of them
614+ // races the dependents past the parent and trips SQLITE_CONSTRAINT.
615+ await db . insert ( games ) . values ( gameRow ) . run ( ) ;
611616 const writes : Promise < unknown > [ ] = [ ] ;
612- // games row is always inserted (any mode, any participant set) so daily
613- // attempts and future analytics have a stable join key.
614- writes . push ( db . insert ( games ) . values ( gameRow ) . run ( ) ) ;
615617 if ( participantRows . length > 0 ) {
616618 writes . push ( db . insert ( gameParticipants ) . values ( participantRows ) . run ( ) ) ;
617619 }
You can’t perform that action at this time.
0 commit comments