Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MBS-11312: Add table to store changes to edit notes
While originally I was just planning to make changes to the edit note table and nothing else, discussion with the team suggested that it would be better to actually have a table that stores the changes. This gives us several benefits: 1) we can easily check if an edit note has been deleted or edited 2) we can see who and when made the change 3) we can store the reason the change was made 4) we can see the original value (useful in case a malicious actor gets access to an admin account somehow, and also useful to find proof of misconduct if the editor posts an edit note, then removes it (after it has been emailed to the intended insultee). This table won't be replicated nor dumped (other than in private dumps).
- Loading branch information
1 parent
247ed9e
commit 4ddcb78
Showing
17 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
\set ON_ERROR_STOP 1 | ||
|
||
BEGIN; | ||
|
||
-- Foreign keys | ||
|
||
ALTER TABLE edit_note_change | ||
ADD CONSTRAINT edit_note_change_fk_edit_note | ||
FOREIGN KEY (edit_note) | ||
REFERENCES edit_note(id); | ||
|
||
ALTER TABLE edit_note_change | ||
ADD CONSTRAINT edit_note_change_fk_change_editor | ||
FOREIGN KEY (change_editor) | ||
REFERENCES editor(id); | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
\set ON_ERROR_STOP 1 | ||
|
||
BEGIN; | ||
|
||
DO $$ | ||
BEGIN | ||
PERFORM 1 FROM pg_type | ||
WHERE typname = 'edit_note_status'; | ||
|
||
IF NOT FOUND THEN | ||
CREATE TYPE edit_note_status AS ENUM ('deleted', 'edited'); | ||
END IF; | ||
END | ||
$$; | ||
|
||
CREATE TABLE edit_note_change | ||
( | ||
id SERIAL, -- PK | ||
status edit_note_status, | ||
edit_note INTEGER NOT NULL, -- references edit_note.id | ||
change_editor INTEGER NOT NULL, -- references editor.id | ||
change_time TIMESTAMP WITH TIME ZONE DEFAULT NOW(), | ||
old_note TEXT NOT NULL, | ||
new_note TEXT NOT NULL, | ||
reason TEXT NOT NULL DEFAULT '' | ||
); | ||
|
||
-- Primary keys | ||
|
||
ALTER TABLE edit_note_change ADD CONSTRAINT edit_note_change_pkey PRIMARY KEY (id); | ||
|
||
-- Indexes | ||
|
||
CREATE INDEX edit_note_change_idx_edit_note ON edit_note_change (edit_note); | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
admin/sql/updates/schema-change/28.master_or_standalone.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- Generated by CompileSchemaScripts.pl from: | ||
-- 20211203-mbs-11312-standalone.sql | ||
\set ON_ERROR_STOP 1 | ||
BEGIN; | ||
SET search_path = musicbrainz, public; | ||
SET LOCAL statement_timeout = 0; | ||
-------------------------------------------------------------------------------- | ||
SELECT '20211203-mbs-11312-standalone.sql'; | ||
|
||
|
||
-- Foreign keys | ||
|
||
ALTER TABLE edit_note_change | ||
ADD CONSTRAINT edit_note_change_fk_edit_note | ||
FOREIGN KEY (edit_note) | ||
REFERENCES edit_note(id); | ||
|
||
ALTER TABLE edit_note_change | ||
ADD CONSTRAINT edit_note_change_fk_change_editor | ||
FOREIGN KEY (change_editor) | ||
REFERENCES editor(id); | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters