internal/store/migrations/0052_org_scope.down.sql
33 lines · 1317 bytes
1-- foreign_keys: off
2-- Back to per-repository rows. An org-scoped row has no repository to go
3-- to; the NOT NULL on repo_id refuses the copy, which fails the migration.
4PRAGMA legacy_alter_table = ON;
5
6ALTER TABLE labels RENAME TO labels_old;
7CREATE TABLE labels (
8 id INTEGER PRIMARY KEY,
9 repo_id INTEGER NOT NULL REFERENCES repos(id) ON DELETE CASCADE,
10 name TEXT NOT NULL,
11 color TEXT NOT NULL DEFAULT '',
12 UNIQUE (repo_id, name)
13);
14INSERT INTO labels (id, repo_id, name, color)
15 SELECT id, repo_id, name, color FROM labels_old;
16DROP TABLE labels_old;
17
18ALTER TABLE milestones RENAME TO milestones_old;
19CREATE TABLE milestones (
20 id INTEGER PRIMARY KEY,
21 repo_id INTEGER NOT NULL REFERENCES repos(id) ON DELETE CASCADE,
22 title TEXT NOT NULL,
23 description TEXT NOT NULL DEFAULT '',
24 due_date TEXT NOT NULL DEFAULT '',
25 state TEXT NOT NULL DEFAULT 'open' CHECK (state IN ('open','closed')),
26 created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
27 UNIQUE (repo_id, title)
28);
29INSERT INTO milestones (id, repo_id, title, description, due_date, state, created_at)
30 SELECT id, repo_id, title, description, due_date, state, created_at FROM milestones_old;
31DROP TABLE milestones_old;
32
33PRAGMA legacy_alter_table = OFF;