Files
play-life/play-life-backend/migrations/020_change_period_to_start_date.sql
poignatov b3a83e1e8f
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 1m5s
feat: замена period_type на start_date в wishlist, обновление UI формы условий
- Добавлена миграция 020 для замены period_type на start_date в score_conditions
- Обновлена функция подсчёта баллов: calculateProjectPointsFromDate вместо calculateProjectPointsForPeriod
- Добавлен компонент DateSelector для выбора даты начала подсчёта
- По умолчанию выбран тип условия 'Баллы'
- Переименованы опции: 'Баллы' и 'Задача'
- Версия: 3.9.3
2026-01-12 17:02:33 +03:00

38 lines
1.9 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- Migration: Change period_type to start_date in score_conditions
-- This allows specifying a start date for counting points instead of period type
-- Date can be in the past or future, NULL means count all time
-- Добавляем новое поле start_date
ALTER TABLE score_conditions
ADD COLUMN IF NOT EXISTS start_date DATE;
-- Миграция данных: для существующих записей с period_type устанавливаем start_date
-- Если period_type = 'week', то start_date = начало текущей недели
-- Если period_type = 'month', то start_date = начало текущего месяца
-- Если period_type = 'year', то start_date = начало текущего года
-- Если period_type IS NULL, то start_date = NULL (за всё время)
UPDATE score_conditions
SET start_date = CASE
WHEN period_type = 'week' THEN DATE_TRUNC('week', CURRENT_DATE)::DATE
WHEN period_type = 'month' THEN DATE_TRUNC('month', CURRENT_DATE)::DATE
WHEN period_type = 'year' THEN DATE_TRUNC('year', CURRENT_DATE)::DATE
ELSE NULL
END
WHERE start_date IS NULL;
-- Обновляем уникальное ограничение (удаляем старое, добавляем новое)
ALTER TABLE score_conditions
DROP CONSTRAINT IF EXISTS unique_score_condition;
ALTER TABLE score_conditions
ADD CONSTRAINT unique_score_condition
UNIQUE (project_id, required_points, start_date);
-- Обновляем комментарии
COMMENT ON COLUMN score_conditions.start_date IS 'Date from which to start counting points. NULL means count all time.';
-- Примечание: поле period_type оставляем пока для обратной совместимости
-- Его можно будет удалить позже после проверки, что всё работает:
-- ALTER TABLE score_conditions DROP COLUMN period_type;