OXYGENHUB
◆ main oxygenhub / crates / hub / migrations-pg / 0105_board_views.sql
1.6 KiB · SQL · last changed Board views: saved views, filter bar, lanes, WIP limits, table, keys, card history (refs #361) 1 day ago source blame history raw
0bc95135 Andy McCall ↶ 1
-- Board views and history (oxygenhub#361, #357): a column's work-in-progress
2
-- limit; a board's saved views, each a layout with its filter, lanes and
3
-- sort; and every card's moves (added, moved, archived, restored, removed),
4
-- from which cumulative flow, cycle time and forecasts are drawn. A move to
5
-- no column (NULL) takes the card off the board. Cards already on boards
6
-- start their history where they are now.
7
ALTER TABLE project_columns ADD COLUMN wip_limit BIGINT;
8
9
CREATE TABLE project_views (
10
    id         BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
11
    project_id BIGINT NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
12
    name       TEXT NOT NULL,
13
    layout     TEXT NOT NULL DEFAULT 'board',
14
    q          TEXT NOT NULL DEFAULT '',
15
    lane       TEXT NOT NULL DEFAULT '',
16
    sort       TEXT NOT NULL DEFAULT '',
17
    position   BIGINT NOT NULL,
18
    created_ms BIGINT NOT NULL,
19
    UNIQUE (project_id, name)
20
);
21
22
CREATE TABLE project_card_moves (
23
    id         BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
24
    project_id BIGINT NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
25
    card_id    BIGINT NOT NULL,
26
    column_id  BIGINT,
27
    at_ms      BIGINT NOT NULL
28
);
29
CREATE INDEX project_card_moves_by_project ON project_card_moves (project_id, at_ms);
30
31
INSERT INTO project_card_moves (project_id, card_id, column_id, at_ms)
32
    SELECT project_id, id, column_id, moved_ms FROM project_cards;
33
INSERT INTO project_card_moves (project_id, card_id, column_id, at_ms)
34
    SELECT project_id, id, NULL, archived_ms FROM project_cards WHERE archived_ms IS NOT NULL;