Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/main/resources/schema.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE users
CREATE TABLE IF NOT EXISTS users
(
id UUID PRIMARY KEY,
created_at timestamptz NOT NULL,
Expand All @@ -8,7 +8,7 @@ CREATE TABLE users
password varchar(60) NOT NULL,
profile_id UUID unique
);
CREATE TABLE channels
CREATE TABLE IF NOT EXISTS channels
(
id UUID PRIMARY KEY,
created_at timestamptz NOT NULL,
Expand All @@ -17,7 +17,7 @@ CREATE TABLE channels
description varchar(500),
type varchar(10) check (type in ('PUBLIC', 'PRIVATE')) NOT NULL
);
CREATE TABLE messages
CREATE TABLE IF NOT EXISTS messages
(
id UUID PRIMARY KEY,
created_at timestamptz NOT NULL,
Expand All @@ -28,7 +28,7 @@ CREATE TABLE messages
FOREIGN KEY (channel_id) REFERENCES channels (id) ON DELETE CASCADE,
FOREIGN KEY (author_id) REFERENCES users (id) ON DELETE SET NULL
);
CREATE TABLE user_statuses
CREATE TABLE IF NOT EXISTS user_statuses
(
id UUID PRIMARY KEY,
created_at timestamptz NOT NULL,
Expand All @@ -37,7 +37,7 @@ CREATE TABLE user_statuses
last_active_at timestamptz NOT NULL,
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
);
CREATE TABLE read_statuses
CREATE TABLE IF NOT EXISTS read_statuses
(
id UUID PRIMARY KEY,
created_at timestamptz NOT NULL,
Expand All @@ -49,16 +49,15 @@ CREATE TABLE read_statuses
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
FOREIGN KEY (channel_id) REFERENCES channels (id) ON DELETE CASCADE
);
CREATE TABLE binary_contents
CREATE TABLE IF NOT EXISTS binary_contents
(
id UUID PRIMARY KEY,
created_at timestamptz NOT NULL,
file_name varchar(255) NOT NULL,
size bigint NOT NULL,
content_type varchar(100) NOT NULL,
bytes bytea NOT NULL
content_type varchar(100) NOT NULL
);
CREATE TABLE message_attachments
CREATE TABLE IF NOT EXISTS message_attachments
(
message_id UUID NOT NULL,
attachment_id UUID NOT NULL,
Expand All @@ -68,6 +67,4 @@ CREATE TABLE message_attachments
);
ALTER TABLE users
ADD CONSTRAINT fk_users_binary_contents FOREIGN KEY (profile_id)
REFERENCES binary_contents (id) ON DELETE SET NULL;
ALTER TABLE binary_contents
DROP COLUMN bytes;
REFERENCES binary_contents (id) ON DELETE SET NULL;