feat: admin routing part 5

This commit is contained in:
Ahmet Kaan GÜMÜŞ 2025-01-28 22:38:14 +03:00
parent c3156aeb41
commit 6d3b6a4e79
35 changed files with 385 additions and 401 deletions

View file

@ -1,10 +1,10 @@
-- Add up migration script here
CREATE TABLE IF NOT EXISTS "role"(
id BIGSERIAL PRIMARY KEY NOT NULL UNIQUE,
role_id BIGSERIAL PRIMARY KEY NOT NULL UNIQUE,
name VARCHAR(16) NOT NULL UNIQUE
);
INSERT INTO "role"(id, name) VALUES (0, 'Builder') ON CONFLICT(id) DO UPDATE SET "name" = 'Builder';
INSERT INTO "role"(id, name) VALUES (1, 'Admin') ON CONFLICT(id) DO UPDATE SET "name" = 'Admin';
INSERT INTO "role"(id, name) VALUES (10, 'Normal') ON CONFLICT(id) DO UPDATE SET "name" = 'Normal';
INSERT INTO "role"(id, name) VALUES (-1, 'Banned') ON CONFLICT(id) DO UPDATE SET "name" = 'Banned';
INSERT INTO "role"(role_id, name) VALUES (0, 'Builder') ON CONFLICT(role_id) DO UPDATE SET "name" = 'Builder';
INSERT INTO "role"(role_id, name) VALUES (1, 'Admin') ON CONFLICT(role_id) DO UPDATE SET "name" = 'Admin';
INSERT INTO "role"(role_id, name) VALUES (10, 'Normal') ON CONFLICT(role_id) DO UPDATE SET "name" = 'Normal';
INSERT INTO "role"(role_id, name) VALUES (-1, 'Banned') ON CONFLICT(role_id) DO UPDATE SET "name" = 'Banned';

View file

@ -5,7 +5,7 @@ CREATE TABLE IF NOT EXISTS "user"(
surname VARCHAR(256) NOT NULL,
gender BOOLEAN NOT NULL,
birth_date DATE NOT NULL,
role_id BIGINT NOT NULL REFERENCES "role" DEFAULT 10,
role_id BIGINT NOT NULL REFERENCES "role"(role_id) DEFAULT 10,
creation_time TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

View file

@ -1,7 +1,7 @@
-- Add up migration script here
CREATE TABLE IF NOT EXISTS "post"(
user_id BIGSERIAL NOT NULL REFERENCES "user"(user_id),
creation_time TIMESTAMPTZ UNIQUE NOT NULL DEFAULT NOW(),
post VARCHAR(8192) NOT NULL UNIQUE,
PRIMARY KEY(user_id, creation_time)
post_id BIGSERIAL PRIMARY KEY NOT NULL UNIQUE,
user_id BIGINT NOT NULL REFERENCES "user"(user_id),
creation_time TIMESTAMPTZ NOT NULL DEFAULT NOW(),
post TEXT NOT NULL UNIQUE
);

View file

@ -1,7 +1,8 @@
-- Add up migration script here
CREATE TABLE IF NOT EXISTS "comment"(
creation_time TIMESTAMPTZ PRIMARY KEY NOT NULL UNIQUE DEFAULT NOW(),
post_creation_time TIMESTAMPTZ NOT NULL REFERENCES "post"(creation_time),
user_id BIGSERIAL NOT NULL REFERENCES "user"(user_id),
comment VARCHAR(8192) NOT NULL
comment_id BIGSERIAL NOT NULL PRIMARY KEY,
user_id BIGINT NOT NULL REFERENCES "user"(user_id),
post_id BIGINT NOT NULL REFERENCES "post"(post_id),
creation_time TIMESTAMPTZ NOT NULL DEFAULT NOW(),
comment TEXT NOT NULL
);

View file

@ -1,5 +1,5 @@
-- Add up migration script here
CREATE TABLE IF NOT EXISTS "interaction"(
id BIGSERIAL PRIMARY KEY NOT NULL UNIQUE,
interaction_id BIGSERIAL PRIMARY KEY NOT NULL UNIQUE,
name VARCHAR(32) UNIQUE NOT NULL
);
);

View file

@ -1,7 +1,8 @@
-- Add up migration script here
CREATE TABLE IF NOT EXISTS "post_interaction"(
interaction_time TIMESTAMPTZ PRIMARY KEY NOT NULL UNIQUE DEFAULT NOW(),
post_creation_time TIMESTAMPTZ NOT NULL REFERENCES "post"(creation_time),
user_id BIGSERIAL NOT NULL REFERENCES "user"(user_id),
interaction_id BIGSERIAL NOT NULL REFERENCES "interaction"(id)
post_id BIGINT NOT NULL REFERENCES "post"(post_id),
user_id BIGINT NOT NULL REFERENCES "user"(user_id),
interaction_time TIMESTAMPTZ NOT NULL DEFAULT NOW(),
interaction_id BIGINT NOT NULL REFERENCES "interaction"(interaction_id),
PRIMARY KEY(post_id, user_id)
);

View file

@ -1,7 +1,8 @@
-- Add up migration script here
CREATE TABLE IF NOT EXISTS "comment_interaction"(
interaction_time TIMESTAMPTZ PRIMARY KEY NOT NULL UNIQUE DEFAULT NOW(),
comment_creation_time TIMESTAMPTZ NOT NULL REFERENCES "comment"(creation_time),
user_id BIGSERIAL NOT NULL REFERENCES "user"(user_id),
interaction_id BIGSERIAL NOT NULL REFERENCES "interaction"(id)
comment_id BIGINT NOT NULL REFERENCES "comment"(comment_id),
user_id BIGINT NOT NULL REFERENCES "user"(user_id),
interaction_time TIMESTAMPTZ NOT NULL DEFAULT NOW(),
interaction_id BIGINT NOT NULL REFERENCES "interaction"(interaction_id),
PRIMARY KEY(comment_id, user_id)
);

View file

@ -1,7 +1,7 @@
-- Add up migration script here
CREATE TABLE IF NOT EXISTS "contact"(
id BIGSERIAL PRIMARY KEY NOT NULL UNIQUE,
contact_id BIGSERIAL PRIMARY KEY NOT NULL UNIQUE,
name VARCHAR(32) NOT NULL UNIQUE
);
INSERT INTO "contact"(id, name) VALUES (0, 'Email') ON CONFLICT(id) DO UPDATE SET "name" = 'Email';
INSERT INTO "contact"(contact_id, name) VALUES (0, 'Email') ON CONFLICT(contact_id) DO UPDATE SET "name" = 'Email';

View file

@ -1,7 +1,7 @@
-- Add up migration script here
CREATE TABLE IF NOT EXISTS "user_contact"(
user_id BIGSERIAL NOT NULL REFERENCES "user"(user_id),
contact_id BIGSERIAL NOT NULL REFERENCES "contact"(id),
contact_id BIGSERIAL NOT NULL REFERENCES "contact"(contact_id),
contact_value VARCHAR(256) NOT NULL,
PRIMARY KEY (user_id, contact_id),
UNIQUE (contact_id, contact_value)