|
| 1 | +<?php |
| 2 | + |
| 3 | +use App\Core\Migration; |
| 4 | + |
| 5 | +/** |
| 6 | + * Add priority column to tasks table. |
| 7 | + * |
| 8 | + * Priority values: |
| 9 | + * -1 = low |
| 10 | + * 0 = medium (default) |
| 11 | + * 1 = high |
| 12 | + * 2 = critical |
| 13 | + * |
| 14 | + * Tasks with higher priority are sorted before lower-priority tasks |
| 15 | + * in the default task list ordering. |
| 16 | + * |
| 17 | + * Migration number: 0056 |
| 18 | + */ |
| 19 | +class AddTaskPriority extends Migration |
| 20 | +{ |
| 21 | + public function up(): void |
| 22 | + { |
| 23 | + $this->db->execute('ALTER TABLE tasks ADD COLUMN priority INTEGER NOT NULL DEFAULT 0'); |
| 24 | + $this->db->execute( |
| 25 | + 'CREATE INDEX IF NOT EXISTS tasks_priority ON tasks (priority)' |
| 26 | + ); |
| 27 | + } |
| 28 | + |
| 29 | + public function down(): void |
| 30 | + { |
| 31 | + // SQLite < 3.35.0 cannot DROP COLUMN. Recreate the table. |
| 32 | + $pdo = $this->db->pdo(); |
| 33 | + |
| 34 | + $pdo->exec(" |
| 35 | + CREATE TABLE tasks_new ( |
| 36 | + id INTEGER NOT NULL, |
| 37 | + title VARCHAR(255) NOT NULL, |
| 38 | + description TEXT, |
| 39 | + status VARCHAR(32) NOT NULL DEFAULT 'open', |
| 40 | + due_at VARCHAR(32), |
| 41 | + entity_type VARCHAR(64), |
| 42 | + entity_id INTEGER, |
| 43 | + created_by_user_id INTEGER, |
| 44 | + created_at VARCHAR(32) NOT NULL, |
| 45 | + updated_at VARCHAR(32) NOT NULL, |
| 46 | + reminder_due_sent_at VARCHAR(32), |
| 47 | + reminder_overdue_sent_at VARCHAR(32), |
| 48 | + deleted_at VARCHAR(32), |
| 49 | + assigned_type TEXT, |
| 50 | + assigned_id INTEGER, |
| 51 | + execution_type TEXT, |
| 52 | + execution_payload TEXT, |
| 53 | + last_run_at VARCHAR(32), |
| 54 | + last_run_status VARCHAR(32), |
| 55 | + last_run_message TEXT, |
| 56 | + schedule_type VARCHAR(32), |
| 57 | + schedule_value TEXT, |
| 58 | + organization_id INTEGER, |
| 59 | +
|
| 60 | + PRIMARY KEY (id), |
| 61 | + FOREIGN KEY (created_by_user_id) REFERENCES users(id) ON DELETE SET NULL |
| 62 | + ) |
| 63 | + "); |
| 64 | + |
| 65 | + $pdo->exec(" |
| 66 | + INSERT INTO tasks_new |
| 67 | + (id, title, description, status, due_at, |
| 68 | + entity_type, entity_id, created_by_user_id, |
| 69 | + created_at, updated_at, |
| 70 | + reminder_due_sent_at, reminder_overdue_sent_at, deleted_at, |
| 71 | + assigned_type, assigned_id, execution_type, execution_payload, |
| 72 | + last_run_at, last_run_status, last_run_message, |
| 73 | + schedule_type, schedule_value, organization_id) |
| 74 | + SELECT |
| 75 | + id, title, description, status, due_at, |
| 76 | + entity_type, entity_id, created_by_user_id, |
| 77 | + created_at, updated_at, |
| 78 | + reminder_due_sent_at, reminder_overdue_sent_at, deleted_at, |
| 79 | + assigned_type, assigned_id, execution_type, execution_payload, |
| 80 | + last_run_at, last_run_status, last_run_message, |
| 81 | + schedule_type, schedule_value, organization_id |
| 82 | + FROM tasks |
| 83 | + "); |
| 84 | + |
| 85 | + $pdo->exec('DROP TABLE tasks'); |
| 86 | + $pdo->exec('ALTER TABLE tasks_new RENAME TO tasks'); |
| 87 | + |
| 88 | + $pdo->exec('CREATE INDEX IF NOT EXISTS tasks_entity ON tasks (entity_type, entity_id)'); |
| 89 | + $pdo->exec('CREATE INDEX IF NOT EXISTS tasks_created_by_user_id ON tasks (created_by_user_id)'); |
| 90 | + $pdo->exec('CREATE INDEX IF NOT EXISTS tasks_status ON tasks (status)'); |
| 91 | + $pdo->exec('CREATE INDEX IF NOT EXISTS tasks_due_at ON tasks (due_at)'); |
| 92 | + $pdo->exec('CREATE INDEX IF NOT EXISTS tasks_deleted_at ON tasks (deleted_at)'); |
| 93 | + $pdo->exec('CREATE INDEX IF NOT EXISTS tasks_assigned_type ON tasks (assigned_type, assigned_id)'); |
| 94 | + } |
| 95 | +} |
0 commit comments