Files
zarinpal-analytics-backend/migrations/000006_growth_coach_completion_guard.sql

20 lines
446 B
PL/PgSQL

BEGIN;
UPDATE golden_steps
SET status = 'IN_PROGRESS',
completed_at = NULL,
updated_at = now()
WHERE action_type = 'METRIC'
AND status = 'COMPLETED'
AND (
current_value IS NULL
OR target IS NULL
OR metric_direction IS NULL
OR (metric_direction = 'INCREASE' AND current_value < target)
OR (metric_direction = 'DECREASE' AND current_value > target)
);
INSERT INTO schema_migrations(version) VALUES (6);
COMMIT;