Files
carvalho-finances/apps/api/internal/migration/sql/006_quests.sql
T
Mlcavalho1andClaude Sonnet 4.6 2277f4375d fix: migration runner idempotente e seeds com UNIQUE constraint
Runner agora checa schema_migrations antes de rodar cada SQL — sem
reexecução de seeds a cada startup. Quests: UNIQUE(title, quest_type).
Cosmetics: UNIQUE(name), tipos corrigidos para hair/shirt/pants/shoes.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-05-26 22:01:48 -03:00

34 lines
1.6 KiB
SQL

CREATE TABLE IF NOT EXISTS quests (
id SERIAL PRIMARY KEY,
title VARCHAR(100) NOT NULL,
description TEXT,
quest_type VARCHAR(20) NOT NULL CHECK (quest_type IN ('daily','weekly','monthly')),
target_count INTEGER,
target_pct NUMERIC(5,2),
xp_reward INTEGER NOT NULL DEFAULT 50,
active BOOLEAN NOT NULL DEFAULT TRUE,
UNIQUE (title, quest_type)
);
CREATE TABLE IF NOT EXISTS player_quests (
id SERIAL PRIMARY KEY,
quest_id INTEGER NOT NULL REFERENCES quests(id) ON DELETE CASCADE,
period VARCHAR(10) NOT NULL,
current_count INTEGER NOT NULL DEFAULT 0,
current_pct NUMERIC(5,2) NOT NULL DEFAULT 0,
completed BOOLEAN NOT NULL DEFAULT FALSE,
completed_at TIMESTAMP WITH TIME ZONE,
claimed BOOLEAN NOT NULL DEFAULT FALSE,
UNIQUE (quest_id, period)
);
INSERT INTO quests (title, description, quest_type, target_count, target_pct, xp_reward) VALUES
('Economista do Mês', 'Poupe ≥40% da receita este mês', 'monthly', NULL, 40, 200),
('Capitão Organizado', 'Importe 1 extrato esta semana', 'weekly', 1, NULL, 50),
('Categorizador Ativo', 'Categorize 5 transações hoje', 'daily', 5, NULL, 30),
('Controlador Semanal', 'Registre ao menos 3 transações esta semana', 'weekly', 3, NULL, 40),
('Mês Sem Surpresas', 'Cubra todas as recorrências do mês', 'monthly', NULL, NULL, 150)
ON CONFLICT (title, quest_type) DO NOTHING;
INSERT INTO schema_migrations (version) VALUES (6) ON CONFLICT DO NOTHING;