This commit is contained in:
@@ -109,3 +109,43 @@ export function migrateModeration(handle: Database.Database): void {
|
||||
cursor = [last.game, last.guid];
|
||||
}
|
||||
}
|
||||
|
||||
/** The migration runner disables foreign keys before opening this transaction. */
|
||||
export function migrateModerationCases(handle: Database.Database): void {
|
||||
const columns = handle.pragma('table_info(moderation_cases)') as { name: string }[];
|
||||
if (!columns.some((column) => column.name === 'priority')) {
|
||||
if (handle.pragma('foreign_keys', { simple: true }))
|
||||
throw new Error('The moderation case migration requires foreign keys to be disabled');
|
||||
// Do not rename the existing parent: archived evidence must keep its
|
||||
// original case reference through the rebuild.
|
||||
handle.exec(`
|
||||
CREATE TABLE moderation_cases_expanded (
|
||||
id TEXT PRIMARY KEY, game TEXT NOT NULL, guid TEXT NOT NULL, title TEXT NOT NULL,
|
||||
status TEXT NOT NULL CHECK(status IN ('open','in_review','escalated','resolved','dismissed',
|
||||
'warning_issued','restriction_applied','no_action','duplicate','appeal_upheld','appeal_denied')),
|
||||
actor_id TEXT NOT NULL, actor TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL, updated_at TEXT NOT NULL, revision INTEGER NOT NULL DEFAULT 1,
|
||||
priority TEXT NOT NULL DEFAULT 'normal' CHECK(priority IN ('low','normal','high','urgent')),
|
||||
assignee_id TEXT REFERENCES auth_users(id) ON DELETE SET NULL
|
||||
);
|
||||
INSERT INTO moderation_cases_expanded(id,game,guid,title,status,actor_id,actor,created_at,updated_at,revision)
|
||||
SELECT id,game,guid,title,status,actor_id,actor,created_at,updated_at,revision FROM moderation_cases;
|
||||
DROP TABLE moderation_cases;
|
||||
ALTER TABLE moderation_cases_expanded RENAME TO moderation_cases;
|
||||
`);
|
||||
}
|
||||
if (
|
||||
!(handle.pragma('table_info(moderation_sanctions)') as { name: string }[]).some(
|
||||
(column) => column.name === 'case_id'
|
||||
)
|
||||
)
|
||||
handle.exec(
|
||||
'ALTER TABLE moderation_sanctions ADD COLUMN case_id TEXT REFERENCES moderation_cases(id) ON DELETE SET NULL'
|
||||
);
|
||||
handle.exec(`
|
||||
CREATE INDEX IF NOT EXISTS moderation_cases_queue ON moderation_cases(status,priority,updated_at);
|
||||
CREATE INDEX IF NOT EXISTS moderation_cases_assignee ON moderation_cases(assignee_id,updated_at);
|
||||
CREATE INDEX IF NOT EXISTS moderation_sanctions_case ON moderation_sanctions(case_id);
|
||||
CREATE INDEX IF NOT EXISTS moderation_events_subject_id ON moderation_events(subject_id,id);
|
||||
`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user