OXYGENHUB
# c30444e35f2e oxygenhub / crates / hub / migrations / 0031_account_disable_delete.sql
1.4 KiB · SQL · last changed Admins disable, enable and delete accounts 1 month ago source blame history raw
1
-- Disabled and deleted accounts (oxygenhub#81). A disabled account is
2
-- refused like a banned one, with its own message, and can be enabled
3
-- again. A deleted account's row goes (its tokens, keys and memberships
4
-- with it); its username is retired so nobody can take it over.
5
ALTER TABLE accounts ADD COLUMN disabled INTEGER NOT NULL DEFAULT 0;
6
7
CREATE TABLE retired_usernames (
8
    username   TEXT PRIMARY KEY COLLATE NOCASE,
9
    retired_ms INTEGER NOT NULL
10
);
11
12
-- A review keeps its author's name when the account is deleted, as issues
13
-- and comments do, rather than going with it.
14
CREATE TABLE proposal_reviews_kept (
15
    id          INTEGER PRIMARY KEY,
16
    proposal_id INTEGER NOT NULL REFERENCES proposals(id) ON DELETE CASCADE,
17
    author_id   INTEGER REFERENCES accounts(id) ON DELETE SET NULL,
18
    author      TEXT NOT NULL DEFAULT '',
19
    verdict     TEXT NOT NULL CHECK (verdict IN ('comment', 'changes', 'approve')),
20
    body        TEXT NOT NULL DEFAULT '',
21
    created_ms  INTEGER NOT NULL
22
);
23
INSERT INTO proposal_reviews_kept (id, proposal_id, author_id, author, verdict, body, created_ms)
24
    SELECT id, proposal_id, author_id, author, verdict, body, created_ms FROM proposal_reviews;
25
DROP TABLE proposal_reviews;
26
ALTER TABLE proposal_reviews_kept RENAME TO proposal_reviews;
27
CREATE INDEX proposal_reviews_by_proposal ON proposal_reviews (proposal_id, created_ms);