Skip to content

Commit 6b4c9e8

Browse files
authored
feat: device, notification, users에 대한 sql문 추가 (#132)
1 parent f55eaa3 commit 6b4c9e8

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
-- Add notification_enabled and last_activity columns to users table
2+
ALTER TABLE users
3+
ADD COLUMN notification_enabled BOOLEAN NOT NULL DEFAULT TRUE COMMENT '알림 수신 동의 여부',
4+
ADD COLUMN last_activity DATETIME(6) NULL COMMENT '마지막 활동 시간';
5+
6+
-- Create device table for multi-device push notification support
7+
CREATE TABLE device
8+
(
9+
id VARCHAR(36) NOT NULL COMMENT '디바이스 ID',
10+
created_at DATETIME(6) NOT NULL COMMENT '생성 시간',
11+
updated_at DATETIME(6) NOT NULL COMMENT '수정 시간',
12+
user_id VARCHAR(36) NOT NULL COMMENT '사용자 ID',
13+
device_id VARCHAR(255) NOT NULL COMMENT '디바이스 고유 ID',
14+
fcm_token VARCHAR(255) NOT NULL COMMENT 'FCM 토큰',
15+
CONSTRAINT pk_device PRIMARY KEY (id)
16+
) COMMENT '사용자 디바이스 정보';
17+
18+
-- Create notification table
19+
CREATE TABLE notification
20+
(
21+
id VARCHAR(36) NOT NULL COMMENT '알림 ID',
22+
created_at DATETIME(6) NOT NULL COMMENT '생성 시간',
23+
updated_at DATETIME(6) NOT NULL COMMENT '수정 시간',
24+
user_id VARCHAR(36) NOT NULL COMMENT '사용자 ID',
25+
title VARCHAR(255) NOT NULL COMMENT '알림 제목',
26+
message VARCHAR(1000) NOT NULL COMMENT '알림 메시지',
27+
notification_type ENUM ('UNRECORDED', 'DORMANT') NOT NULL COMMENT '알림 타입',
28+
is_read BOOLEAN NOT NULL DEFAULT FALSE COMMENT '읽음 여부',
29+
is_sent BOOLEAN NOT NULL DEFAULT FALSE COMMENT '전송 여부',
30+
sent_at DATETIME(6) NULL COMMENT '전송 시간',
31+
CONSTRAINT pk_notification PRIMARY KEY (id)
32+
) COMMENT '사용자 알림 정보';
33+
34+
-- Create indexes for actual query usage only
35+
CREATE INDEX idx_device_user_id ON device (user_id);
36+
CREATE INDEX idx_device_device_id ON device (device_id);
37+
CREATE INDEX idx_device_fcm_token ON device (fcm_token);
38+
39+
CREATE INDEX idx_notification_user_id ON notification (user_id);
40+
CREATE INDEX idx_notification_is_sent ON notification (is_sent);
41+
42+
-- Composite index for: WHERE last_activity < ? AND notification_enabled = true
43+
CREATE INDEX idx_users_last_activity_notification ON users (last_activity, notification_enabled);

0 commit comments

Comments
 (0)