You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
autohero/backend/migrations/000004_hero_position_and_lo...

20 lines
891 B
SQL

-- 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);