Skip to content

Commit

Permalink
fix: sql 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
facewise committed May 9, 2024
1 parent 73bf6b7 commit c37ec00
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
DROP TABLE IF EXISTS bread_diary_event;
CREATE TABLE bread_diary_event
(
diary_id BIGINT NOT NULL,
created_at datetime NULL,
modified_at datetime NULL,
`description` VARCHAR(2000) NOT NULL DEFAULT '',
state VARCHAR(255) NOT NULL,
CONSTRAINT pk_breaddiaryevent PRIMARY KEY (diary_id)
);

ALTER TABLE bread_diary_event
ADD CONSTRAINT FK_BREADDIARYEVENT_ON_DIARY FOREIGN KEY (diary_id) REFERENCES bread_diary (id);

DROP TABLE IF EXISTS user_point;
CREATE TABLE user_point
(
user_id BIGINT NOT NULL,
created_at datetime NULL,
modified_at datetime NULL,
total_point INT NOT NULL,
CONSTRAINT pk_userpoint PRIMARY KEY (user_id)
);

ALTER TABLE user_point
ADD CONSTRAINT FK_USERPOINT_ON_USER FOREIGN KEY (user_id) REFERENCES user (id);

DROP TABLE IF EXISTS user_point_history;
CREATE TABLE user_point_history
(
id BIGINT NOT NULL,
created_at datetime NULL,
modified_at datetime NULL,
user_id BIGINT NOT NULL,
point INT NOT NULL,
grand_total_point INT NOT NULL,
type VARCHAR(255) NOT NULL,
`description` VARCHAR(2000) NOT NULL DEFAULT '',
target_id BIGINT NULL,
CONSTRAINT pk_userpointhistory PRIMARY KEY (id)
);

ALTER TABLE challenge
CHANGE start_datetime start_date_time datetime;
ALTER TABLE challenge
CHANGE end_datetime end_date_time datetime;
63 changes: 26 additions & 37 deletions src/main/resources/db/migration/V3__event_point_related_table.sql
Original file line number Diff line number Diff line change
@@ -1,44 +1,33 @@
DROP TABLE IF EXISTS bread_diary_event;
CREATE TABLE bread_diary_event
(
diary_id BIGINT NOT NULL,
created_at datetime NULL,
modified_at datetime NULL,
`description` VARCHAR(2000) NOT NULL DEFAULT '',
state VARCHAR(255) NOT NULL,
CONSTRAINT pk_breaddiaryevent PRIMARY KEY (diary_id)
CREATE TABLE `bread_diary_event` (
`diary_id` bigint PRIMARY KEY ,
`state` varchar(255) NOT NULL DEFAULT 'PENDING',
`point` int NOT NULL DEFAULT 0,
`description` varchar(4000) NOT NULL DEFAULT '',
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
);

ALTER TABLE bread_diary_event
ADD CONSTRAINT FK_BREADDIARYEVENT_ON_DIARY FOREIGN KEY (diary_id) REFERENCES bread_diary (id);
CREATE TABLE `point_history` (
`id` bigint auto_increment PRIMARY KEY,
`user_id` bigint NOT NULL,
`target_id` bigint,
`point` int NOT NULL DEFAULT 0,
`grand_total_point` int NOT NULL DEFAULT 0,
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`type` varchar(255) NOT NULL DEFAULT 'ETC',
`description` varchar(4000) NOT NULL DEFAULT ''
);

DROP TABLE IF EXISTS user_point;
CREATE TABLE user_point
(
user_id BIGINT NOT NULL,
created_at datetime NULL,
modified_at datetime NULL,
total_point INT NOT NULL,
CONSTRAINT pk_userpoint PRIMARY KEY (user_id)
CREATE TABLE `user_point` (
`user_id` bigint PRIMARY KEY,
`total_point` int NOT NULL DEFAULT 0,
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
);

ALTER TABLE user_point
ADD CONSTRAINT FK_USERPOINT_ON_USER FOREIGN KEY (user_id) REFERENCES user (id);
ALTER TABLE `bread_diary_event` ADD FOREIGN KEY (`diary_id`) REFERENCES `bread_diary` (`id`);

DROP TABLE IF EXISTS user_point_history;
CREATE TABLE user_point_history
(
id BIGINT NOT NULL,
created_at datetime NULL,
modified_at datetime NULL,
user_id BIGINT NOT NULL,
point INT NOT NULL,
grand_total_point INT NOT NULL,
type VARCHAR(255) NOT NULL,
`description` VARCHAR(2000) NOT NULL DEFAULT '',
target_id BIGINT NULL,
CONSTRAINT pk_userpointhistory PRIMARY KEY (id)
);
ALTER TABLE `point_history` ADD FOREIGN KEY (`user_id`) REFERENCES `user` (`id`);

alter table challenge CHANGE start_datetime start_date_time datetime;
ALTER TABLE challenge CHANGE end_datetime end_date_time datetime;
ALTER TABLE `user_point` ADD FOREIGN KEY (`user_id`) REFERENCES `user` (`id`);

0 comments on commit c37ec00

Please sign in to comment.