Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL: Schema Changes for Administration System #993

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions sql/migrations/2023-05-29-admin_logs/down.sql
@@ -0,0 +1,6 @@
BEGIN TRANSACTION;

DROP TABLE IF EXISTS bookbrainz.admin_log;
DROP TYPE IF EXISTS bookbrainz.admin_action_type;

COMMIT;
25 changes: 25 additions & 0 deletions sql/migrations/2023-05-29-admin_logs/up.sql
@@ -0,0 +1,25 @@
BEGIN TRANSACTION;

CREATE TYPE bookbrainz.admin_action_type AS ENUM (
'Change Privileges'
);

COMMIT;

BEGIN TRANSACTION;

CREATE TABLE bookbrainz.admin_log (
id SERIAL PRIMARY KEY,
admin_id INT NOT NULL,
target_user_id INT NOT NULL,
old_privs INT,
new_privs INT,
action_type bookbrainz.admin_action_type NOT NULL,
time TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT timezone('UTC'::TEXT, now()),
note VARCHAR NOT NULL
);

ALTER TABLE bookbrainz.admin_log ADD FOREIGN KEY (admin_id) REFERENCES bookbrainz.editor(id);
ALTER TABLE bookbrainz.admin_log ADD FOREIGN KEY (target_user_id) REFERENCES bookbrainz.editor(id);

COMMIT;
5 changes: 5 additions & 0 deletions sql/migrations/2023-05-29-user_privileges/up.sql
@@ -0,0 +1,5 @@
BEGIN TRANSACTION;

ALTER TABLE bookbrainz.editor ADD COLUMN privs INT NOT NULL DEFAULT 1;

COMMIT;
19 changes: 19 additions & 0 deletions sql/schemas/bookbrainz.sql
Expand Up @@ -20,6 +20,10 @@ CREATE TYPE bookbrainz.external_service_oauth_type AS ENUM (
'critiquebrainz'
);

CREATE TYPE bookbrainz.admin_action_type AS ENUM (
'Change Privileges'
);

CREATE TABLE bookbrainz.editor_type (
id SERIAL PRIMARY KEY,
label VARCHAR(255) NOT NULL CHECK (label <> '')
Expand All @@ -37,6 +41,7 @@ CREATE TABLE bookbrainz.editor (
type_id INT NOT NULL,
gender_id INT,
area_id INT,
privs INT NOT NULL DEFAULT 1,
revisions_applied INT NOT NULL DEFAULT 0 CHECK (revisions_applied >= 0),
revisions_reverted INT NOT NULL DEFAULT 0 CHECK (revisions_reverted >= 0),
total_revisions INT NOT NULL DEFAULT 0 CHECK (total_revisions >= 0),
Expand All @@ -56,6 +61,20 @@ CREATE TABLE bookbrainz.editor__language (
)
);

CREATE TABLE bookbrainz.admin_log (
id SERIAL PRIMARY KEY,
admin_id INT NOT NULL,
target_user_id INT NOT NULL,
old_privs INT,
new_privs INT,
action_type bookbrainz.admin_action_type NOT NULL,
time TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT timezone('UTC'::TEXT, now()),
note VARCHAR NOT NULL
);

ALTER TABLE bookbrainz.admin_log ADD FOREIGN KEY (admin_id) REFERENCES bookbrainz.editor (id);
ALTER TABLE bookbrainz.admin_log ADD FOREIGN KEY (target_user_id) REFERENCES bookbrainz.editor (id);

CREATE TABLE bookbrainz.entity (
bbid UUID PRIMARY KEY DEFAULT public.uuid_generate_v4(),
type bookbrainz.entity_type NOT NULL
Expand Down