-- migrations/001_game_sessions.sql
-- One saved Game of Life session per user, stored as a JSONB snapshot.
-- Run with: psql $DATABASE_URL -f migrations/001_game_sessions.sql

CREATE TABLE IF NOT EXISTS game_sessions (
  id          SERIAL PRIMARY KEY,
  user_id     INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
  state       JSONB   NOT NULL,
  updated_at  TIMESTAMPTZ NOT NULL DEFAULT now(),
  CONSTRAINT game_sessions_user_unique UNIQUE (user_id)
);

CREATE INDEX IF NOT EXISTS idx_game_sessions_user ON game_sessions (user_id);
