Skip to content

Commit 53ef89d

Browse files
authored
refactor: schema.sql에 bytes 제거된 테이블 생성하게 변경 & 테이블 없을 시 생성하게 개선
refactor: schema.sql에 bytes 제거된 테이블 생성하게 변경 & 테이블 없을 시 생성하게 개선
2 parents b580bff + 24ed017 commit 53ef89d

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/main/resources/schema.sql

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE TABLE users
1+
CREATE TABLE IF NOT EXISTS users
22
(
33
id UUID PRIMARY KEY,
44
created_at timestamptz NOT NULL,
@@ -8,7 +8,7 @@ CREATE TABLE users
88
password varchar(60) NOT NULL,
99
profile_id UUID unique
1010
);
11-
CREATE TABLE channels
11+
CREATE TABLE IF NOT EXISTS channels
1212
(
1313
id UUID PRIMARY KEY,
1414
created_at timestamptz NOT NULL,
@@ -17,7 +17,7 @@ CREATE TABLE channels
1717
description varchar(500),
1818
type varchar(10) check (type in ('PUBLIC', 'PRIVATE')) NOT NULL
1919
);
20-
CREATE TABLE messages
20+
CREATE TABLE IF NOT EXISTS messages
2121
(
2222
id UUID PRIMARY KEY,
2323
created_at timestamptz NOT NULL,
@@ -28,7 +28,7 @@ CREATE TABLE messages
2828
FOREIGN KEY (channel_id) REFERENCES channels (id) ON DELETE CASCADE,
2929
FOREIGN KEY (author_id) REFERENCES users (id) ON DELETE SET NULL
3030
);
31-
CREATE TABLE user_statuses
31+
CREATE TABLE IF NOT EXISTS user_statuses
3232
(
3333
id UUID PRIMARY KEY,
3434
created_at timestamptz NOT NULL,
@@ -37,7 +37,7 @@ CREATE TABLE user_statuses
3737
last_active_at timestamptz NOT NULL,
3838
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
3939
);
40-
CREATE TABLE read_statuses
40+
CREATE TABLE IF NOT EXISTS read_statuses
4141
(
4242
id UUID PRIMARY KEY,
4343
created_at timestamptz NOT NULL,
@@ -49,16 +49,15 @@ CREATE TABLE read_statuses
4949
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
5050
FOREIGN KEY (channel_id) REFERENCES channels (id) ON DELETE CASCADE
5151
);
52-
CREATE TABLE binary_contents
52+
CREATE TABLE IF NOT EXISTS binary_contents
5353
(
5454
id UUID PRIMARY KEY,
5555
created_at timestamptz NOT NULL,
5656
file_name varchar(255) NOT NULL,
5757
size bigint NOT NULL,
58-
content_type varchar(100) NOT NULL,
59-
bytes bytea NOT NULL
58+
content_type varchar(100) NOT NULL
6059
);
61-
CREATE TABLE message_attachments
60+
CREATE TABLE IF NOT EXISTS message_attachments
6261
(
6362
message_id UUID NOT NULL,
6463
attachment_id UUID NOT NULL,
@@ -68,6 +67,4 @@ CREATE TABLE message_attachments
6867
);
6968
ALTER TABLE users
7069
ADD CONSTRAINT fk_users_binary_contents FOREIGN KEY (profile_id)
71-
REFERENCES binary_contents (id) ON DELETE SET NULL;
72-
ALTER TABLE binary_contents
73-
DROP COLUMN bytes;
70+
REFERENCES binary_contents (id) ON DELETE SET NULL;

0 commit comments

Comments
 (0)