CREATE TABLE IF NOT EXISTS "achievements" (
achievement_id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description TEXT,
required_action VARCHAR(255) NOT NULL,
threshold INT NOT NULL,
bar_id INT,
required_days INT[] DEFAULT NULL,
specific_date DATE DEFAULT NULL,
time_restricted BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT NOW()
);
CREATE TABLE IF NOT EXISTS "user_achievements_mapping" (
user_id INT REFERENCES users(id) ON DELETE CASCADE,
achievement_id INT REFERENCES achievements(achievement_id) ON DELETE CASCADE,
progress_total INT DEFAULT 0,
progress_days INT[] DEFAULT '{}',
progress_week INT,
progress_year INT,
achieved_at TIMESTAMP,
PRIMARY KEY (user_id, achievement_id)
);