| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
ALTER TABLE tasks ADD COLUMN completed_at TEXT; |
| 5 |
|
| 6 |
UPDATE tasks SET completed_at = created_at WHERE status = 'Completed'; |
| 7 |
|
| 8 |
CREATE INDEX idx_tasks_completed_at ON tasks(completed_at) WHERE completed_at IS NOT NULL; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
DROP TRIGGER IF EXISTS sync_trg_tasks_insert; |
| 13 |
CREATE TRIGGER IF NOT EXISTS sync_trg_tasks_insert |
| 14 |
AFTER INSERT ON tasks |
| 15 |
WHEN (SELECT value FROM sync_state WHERE key = 'applying_remote') != '1' |
| 16 |
BEGIN |
| 17 |
INSERT INTO sync_changelog (table_name, op, row_id, data) |
| 18 |
VALUES ('tasks', 'INSERT', NEW.id, json_object( |
| 19 |
'id', NEW.id, |
| 20 |
'project_id', NEW.project_id, |
| 21 |
'description', NEW.description, |
| 22 |
'status', NEW.status, |
| 23 |
'priority', NEW.priority, |
| 24 |
'due', NEW.due, |
| 25 |
'tags', NEW.tags, |
| 26 |
'urgency', NEW.urgency, |
| 27 |
'recurrence', NEW.recurrence, |
| 28 |
'created_at', NEW.created_at, |
| 29 |
'user_id', NEW.user_id, |
| 30 |
'recurrence_parent_id', NEW.recurrence_parent_id, |
| 31 |
'source_email_id', NEW.source_email_id, |
| 32 |
'snoozed_until', NEW.snoozed_until, |
| 33 |
'waiting_for_response', NEW.waiting_for_response, |
| 34 |
'waiting_since', NEW.waiting_since, |
| 35 |
'expected_response_date', NEW.expected_response_date, |
| 36 |
'scheduled_start', NEW.scheduled_start, |
| 37 |
'scheduled_duration', NEW.scheduled_duration, |
| 38 |
'is_focus', NEW.is_focus, |
| 39 |
'focus_set_at', NEW.focus_set_at, |
| 40 |
'contact_id', NEW.contact_id, |
| 41 |
'milestone_id', NEW.milestone_id, |
| 42 |
'completed_at', NEW.completed_at |
| 43 |
)); |
| 44 |
END; |
| 45 |
|
| 46 |
DROP TRIGGER IF EXISTS sync_trg_tasks_update; |
| 47 |
CREATE TRIGGER IF NOT EXISTS sync_trg_tasks_update |
| 48 |
AFTER UPDATE ON tasks |
| 49 |
WHEN (SELECT value FROM sync_state WHERE key = 'applying_remote') != '1' |
| 50 |
BEGIN |
| 51 |
INSERT INTO sync_changelog (table_name, op, row_id, data) |
| 52 |
VALUES ('tasks', 'UPDATE', NEW.id, json_object( |
| 53 |
'id', NEW.id, |
| 54 |
'project_id', NEW.project_id, |
| 55 |
'description', NEW.description, |
| 56 |
'status', NEW.status, |
| 57 |
'priority', NEW.priority, |
| 58 |
'due', NEW.due, |
| 59 |
'tags', NEW.tags, |
| 60 |
'urgency', NEW.urgency, |
| 61 |
'recurrence', NEW.recurrence, |
| 62 |
'created_at', NEW.created_at, |
| 63 |
'user_id', NEW.user_id, |
| 64 |
'recurrence_parent_id', NEW.recurrence_parent_id, |
| 65 |
'source_email_id', NEW.source_email_id, |
| 66 |
'snoozed_until', NEW.snoozed_until, |
| 67 |
'waiting_for_response', NEW.waiting_for_response, |
| 68 |
'waiting_since', NEW.waiting_since, |
| 69 |
'expected_response_date', NEW.expected_response_date, |
| 70 |
'scheduled_start', NEW.scheduled_start, |
| 71 |
'scheduled_duration', NEW.scheduled_duration, |
| 72 |
'is_focus', NEW.is_focus, |
| 73 |
'focus_set_at', NEW.focus_set_at, |
| 74 |
'contact_id', NEW.contact_id, |
| 75 |
'milestone_id', NEW.milestone_id, |
| 76 |
'completed_at', NEW.completed_at |
| 77 |
)); |
| 78 |
END; |
| 79 |
|