-- Migration: add hero position, potions, and adventure log.

-- Hero position persists across sessions so the client can restore the visual location.
ALTER TABLE heroes ADD COLUMN IF NOT EXISTS position_x DOUBLE PRECISION NOT NULL DEFAULT 0;
ALTER TABLE heroes ADD COLUMN IF NOT EXISTS position_y DOUBLE PRECISION NOT NULL DEFAULT 0;

-- Potions inventory (healing potions from monster drops).
ALTER TABLE heroes ADD COLUMN IF NOT EXISTS potions INT NOT NULL DEFAULT 0;

-- Adventure log: a chronological list of notable in-game events per hero.
CREATE TABLE IF NOT EXISTS adventure_log (
    id         BIGSERIAL PRIMARY KEY,
    hero_id    BIGINT NOT NULL REFERENCES heroes(id) ON DELETE CASCADE,
    message    TEXT NOT NULL,
    created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE INDEX IF NOT EXISTS idx_adventure_log_hero_created
    ON adventure_log (hero_id, created_at DESC);
