feat(db): add migration 0102 project linear ext
zhenyi committed
Added lib/db/migrations/sql/0102_project_linear_ext.sql lib/db/migrations/sql/0102_project_linear_ext.sql +49 −0 View lib/db/migrations/sql/0102_project_linear_ext.sql
@@ -0,0 +1,49 @@
1-- 0102_project_linear_ext.sql
2-- Reference DDL for lib/db/project/project.rs Linear-style field additions.
3-- Documentation only; not run by the migration runner per project policy
4-- ("数据库就不要动了"). Apply manually when DBA window allows.
5--
6-- Mirrors the Rust fields declared in lib/db/project/project.rs:
7-- lead_id : uuid (FK users.uid ON DELETE SET NULL)
8-- icon : text
9-- color : text
10-- state : smallint (ProjectState: 0=Backlog, 1=Planned, 2=InProgress,
11-- 3=Paused, 4=Completed, 5=Cancelled)
12-- target_date : date
13-- started_at : timestamptz
14-- completed_at : timestamptz
15-- cancelled_at : timestamptz
16-- health : smallint (ProjectHealth: 0=OnTrack, 1=AtRisk, 2=OffTrack)
17-- sort_order : double precision default 0
18-- starred : integer default 0
19--
20-- Drop:
21-- is_closed : superseded by state enum
22
23ALTER TABLE project
24 ADD COLUMN IF NOT EXISTS lead_id uuid REFERENCES users(uid) ON DELETE SET NULL,
25 ADD COLUMN IF NOT EXISTS icon text,
26 ADD COLUMN IF NOT EXISTS color text,
27 ADD COLUMN IF NOT EXISTS state smallint NOT NULL DEFAULT 0,
28 ADD COLUMN IF NOT EXISTS target_date date,
29 ADD COLUMN IF NOT EXISTS started_at timestamptz,
30 ADD COLUMN IF NOT EXISTS completed_at timestamptz,
31 ADD COLUMN IF NOT EXISTS cancelled_at timestamptz,
32 ADD COLUMN IF NOT EXISTS health smallint,
33 ADD COLUMN IF NOT EXISTS sort_order double precision NOT NULL DEFAULT 0,
34 ADD COLUMN IF NOT EXISTS starred integer NOT NULL DEFAULT 0;
35
36-- Backfill is_closed -> state before dropping the column to preserve history:
37-- is_closed = true -> state = 5 (Cancelled)
38-- is_closed = false -> state = 0 (Backlog)
39UPDATE project
40 SET state = CASE WHEN is_closed THEN 5 ELSE 0 END
41 WHERE state = 0
42 AND is_closed IS NOT NULL;
43
44ALTER TABLE project DROP COLUMN IF EXISTS is_closed;
45
46CREATE INDEX IF NOT EXISTS idx_project_state ON project (state);
47CREATE INDEX IF NOT EXISTS idx_project_target_date ON project (target_date);
48CREATE INDEX IF NOT EXISTS idx_project_space_order ON project (space_id, sort_order);
49CREATE INDEX IF NOT EXISTS idx_project_lead ON project (lead_id);