router : api request 처리 ( 지금은 채팅관련 api만 있으므로 chat.js만 만들어놈 )
util : 공통 모듈 처리
view : 화면 처리
server.js : 소켓관련 로직 처리
[ 데이터베이스 생성 ]
create DATABASE chatDb default character set utf8 collate utf8_general_ci;
채팅 방 테이블 ( chatRoom )
현재 채팅중인 방 리스트 ( 방이 만들어질때 insert되고 방이 없어질때 delete 된다. )
create table chatRoom (
id int not null auto_increment,
title varchar(50) not null,
join_member_count int not null,
created datetime default current_timestamp,
primary key(id)
);
채팅 방 참여 인원 테이블 ( chatMember )
현재 채팅방에 있는 맴버 리스트 ( 맴버가 방에 참여할때 insert되고 방에서 나갈때 delete 된다. )
create table chatMember (
id int not null auto_increment,
nickname varchar(50) not null,
room_id int not null,
socket_id varchar(50),
join_time datetime default current_timestamp,
primary key(id),
foreign key(room_id) references chatRoom(id)
);
채팅 이력 테이블 ( chatMsg )
채팅방에서 채팅을 치면 이력이 남는다. -> 해당 방이 삭제되면 같이 delete 됨.
create table chatMsg (
id int not null auto_increment,
room_id int not null,
user_id int not null,
content varchar(100) not null,
chat_time datetime default current_timestamp,
primary key(id),
foreign key(room_id) references chatRoom(id),
foreign key(user_id) references chatMember(id)
);