-- 任务存档表：按 player_id 存活跃任务与已完成任务，供 QuestManager 云端同步
-- 在 Supabase SQL Editor 中执行一次即可

CREATE TABLE IF NOT EXISTS quest_saves (
  player_id TEXT PRIMARY KEY,
  active_quests JSONB NOT NULL DEFAULT '{}',
  completed_quests JSONB NOT NULL DEFAULT '[]',
  updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

-- 可选：允许匿名读写（与当前 anon key 一致）
ALTER TABLE quest_saves ENABLE ROW LEVEL SECURITY;

CREATE POLICY "Allow anon read and write quest_saves"
  ON quest_saves FOR ALL
  TO anon
  USING (true)
  WITH CHECK (true);
