source: db-scripts/migrations/V001__expand_tasks_table.sql@ 447c39f

Last change on this file since 447c39f was 447c39f, checked in by Andrej <asumanovski@…>, 2 weeks ago

Improved UI and small fixes

  • Property mode set to 100644
File size: 1.6 KB
Line 
1-- Flyway Migration: Expand TASKS table with description, due_date, priority, and status enum
2-- This migration adds new columns to support custom tracking tasks with enhanced details.
3-- Daily discipline tasks will use NULL for these optional fields.
4
5SET search_path TO trekr;
6
7-- Create ENUM type for task status
8CREATE TYPE task_status AS ENUM ('NOT_STARTED', 'IN_PROGRESS', 'FINISHED');
9
10-- Add new columns to TASKS table
11ALTER TABLE trekr.tasks
12ADD COLUMN description TEXT,
13ADD COLUMN due_date DATE,
14ADD COLUMN priority VARCHAR(10) DEFAULT 'MEDIUM' CHECK (priority IN ('LOW', 'MEDIUM', 'HIGH')),
15ADD COLUMN status task_status DEFAULT 'NOT_STARTED';
16
17-- For backwards compatibility, migrate is_finished to status
18-- is_finished = true → status = FINISHED
19-- is_finished = false → status = NOT_STARTED
20UPDATE trekr.tasks
21SET status = CASE
22 WHEN is_finished = true THEN 'FINISHED'::task_status
23 ELSE 'NOT_STARTED'::task_status
24END;
25
26-- Drop the is_finished column (after migration)
27ALTER TABLE trekr.tasks
28DROP COLUMN is_finished;
29
30-- Add index for filtering tasks by status and custom_tracking_id
31CREATE INDEX idx_tasks_custom_tracking_status
32ON trekr.tasks(custom_tracking_id, status)
33WHERE custom_tracking_id IS NOT NULL;
34
35-- Add index for filtering by discipline_user_id and status (for daily completion computation)
36CREATE INDEX idx_tasks_discipline_status
37ON trekr.tasks(discipline_user_id, status)
38WHERE discipline_user_id IS NOT NULL;
39
40-- Add index for due_date filtering (useful for reports)
41CREATE INDEX idx_tasks_due_date
42ON trekr.tasks(due_date)
43WHERE due_date IS NOT NULL;
44
Note: See TracBrowser for help on using the repository browser.