OXYGENHUB
# 8933faff2043 oxygenhub / crates / hub / migrations / 0015_projects.sql
1.5 KiB · SQL · last changed Projects: boards of issues, proposals and notes across an owner's repositories, with columns, cards moved without JavaScript, private projects, and the projects shown on issues and proposals 1 month ago source blame history raw
1
-- Projects: boards of issues, proposals and notes across one owner's
2
-- repositories (hub spec §8.2).
3
4
CREATE TABLE projects (
5
    id          INTEGER PRIMARY KEY,
6
    owner       TEXT NOT NULL,
7
    number      INTEGER NOT NULL,
8
    title       TEXT NOT NULL,
9
    description TEXT NOT NULL DEFAULT '',
10
    public      INTEGER NOT NULL DEFAULT 1,
11
    closed      INTEGER NOT NULL DEFAULT 0,
12
    created_ms  INTEGER NOT NULL,
13
    updated_ms  INTEGER NOT NULL,
14
    UNIQUE (owner, number)
15
);
16
17
CREATE TABLE project_columns (
18
    id         INTEGER PRIMARY KEY,
19
    project_id INTEGER NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
20
    name       TEXT NOT NULL,
21
    position   INTEGER NOT NULL
22
);
23
CREATE INDEX project_columns_by_project ON project_columns (project_id, position);
24
25
CREATE TABLE project_cards (
26
    id         INTEGER PRIMARY KEY,
27
    project_id INTEGER NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
28
    column_id  INTEGER NOT NULL REFERENCES project_columns(id) ON DELETE CASCADE,
29
    position   INTEGER NOT NULL,
30
    kind       TEXT NOT NULL CHECK (kind IN ('issue', 'proposal', 'note')),
31
    repo_id    INTEGER REFERENCES repositories(id) ON DELETE CASCADE,
32
    number     INTEGER,
33
    note       TEXT NOT NULL DEFAULT '',
34
    added_by   TEXT NOT NULL DEFAULT '',
35
    created_ms INTEGER NOT NULL
36
);
37
CREATE INDEX project_cards_by_column ON project_cards (column_id, position);
38
CREATE UNIQUE INDEX project_cards_once ON project_cards (project_id, repo_id, number) WHERE kind <> 'note';