-- +goose Up
-- Stage 17: a per-(game, account) draft the server persists across reloads and devices —
-- the player's preferred rack tile order (#4) and the tiles they have laid on the board but
-- not yet submitted (#5/#6). board_tiles is reset when an opponent's committed move overlaps
-- one of its cells (the draft can no longer be placed). Queried with raw SQL, so no
-- generated jet code is needed.
SET search_path = backend, pg_catalog;

CREATE TABLE game_drafts (
    game_id     uuid        NOT NULL REFERENCES games (game_id) ON DELETE CASCADE,
    account_id  uuid        NOT NULL REFERENCES accounts (account_id) ON DELETE CASCADE,
    rack_order  text        NOT NULL DEFAULT '',
    board_tiles jsonb       NOT NULL DEFAULT '[]',
    updated_at  timestamptz NOT NULL DEFAULT now(),
    PRIMARY KEY (game_id, account_id)
);

-- +goose Down
SET search_path = backend, pg_catalog;

DROP TABLE game_drafts;
