From 19277279e00df30387a27de0a95156e6101416b1 Mon Sep 17 00:00:00 2001 From: middlefitting Date: Wed, 10 Jan 2024 16:23:38 +0900 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20flyway=20migration=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...g_5th.sql => V1.1__migration_42gg_5th.sql} | 0 .../db/migration/V1.1__migration_42gg_v2.sql | 337 ------------------ .../V1.2__team_and_teamuser_cascade.sql | 19 - ...1.2__update_tournament_content_column.sql} | 0 ...1.3__add_prevent_delete_season_trigger.sql | 12 - .../V1.4__pchange_add_is_checked_column.sql | 3 - ...V1.5__insert_pchange_normal_ppp_result.sql | 19 - src/main/resources/db/migration/V1__init.sql | 280 +++++++++++++++ .../db/migration/V2.1__add_item_creator.sql | 5 - .../db/migration/V2.2__add_item_type.sql | 2 - .../V2.3__add_megaphone_receiptId.sql | 7 - .../V2.4__modify_item_content_columns.sql | 10 - ...V2.5__add_userImage_and_user_image_uri.sql | 18 - .../db/migration/V2__migration_42gg_4th.sql | 102 ------ 14 files changed, 280 insertions(+), 534 deletions(-) rename src/main/resources/db/migration/{V3__migration_42gg_5th.sql => V1.1__migration_42gg_5th.sql} (100%) delete mode 100644 src/main/resources/db/migration/V1.1__migration_42gg_v2.sql delete mode 100644 src/main/resources/db/migration/V1.2__team_and_teamuser_cascade.sql rename src/main/resources/db/migration/{V3.1__update_tournament_content_column.sql => V1.2__update_tournament_content_column.sql} (100%) delete mode 100644 src/main/resources/db/migration/V1.3__add_prevent_delete_season_trigger.sql delete mode 100644 src/main/resources/db/migration/V1.4__pchange_add_is_checked_column.sql delete mode 100644 src/main/resources/db/migration/V1.5__insert_pchange_normal_ppp_result.sql delete mode 100644 src/main/resources/db/migration/V2.1__add_item_creator.sql delete mode 100644 src/main/resources/db/migration/V2.2__add_item_type.sql delete mode 100644 src/main/resources/db/migration/V2.3__add_megaphone_receiptId.sql delete mode 100644 src/main/resources/db/migration/V2.4__modify_item_content_columns.sql delete mode 100644 src/main/resources/db/migration/V2.5__add_userImage_and_user_image_uri.sql delete mode 100644 src/main/resources/db/migration/V2__migration_42gg_4th.sql diff --git a/src/main/resources/db/migration/V3__migration_42gg_5th.sql b/src/main/resources/db/migration/V1.1__migration_42gg_5th.sql similarity index 100% rename from src/main/resources/db/migration/V3__migration_42gg_5th.sql rename to src/main/resources/db/migration/V1.1__migration_42gg_5th.sql diff --git a/src/main/resources/db/migration/V1.1__migration_42gg_v2.sql b/src/main/resources/db/migration/V1.1__migration_42gg_v2.sql deleted file mode 100644 index fcd7a9a6e..000000000 --- a/src/main/resources/db/migration/V1.1__migration_42gg_v2.sql +++ /dev/null @@ -1,337 +0,0 @@ -### delete key ### -alter table current_match drop foreign key FK4qtnfmeqkj0iy1qeghm6ywb6n; -alter table current_match drop foreign key FKl53dqtyiaemmm1tqdsdj55ng2; -alter table current_match drop foreign key FKmaa4irkiicemkq2gl3t0bqn6a; -alter table slot_team_user drop foreign key FKg9emy523qv3kx98dkb3xc8m9x; -alter table slot_team_user drop foreign key FKkr5xbxj8y5gcqivythvkwxmqw; -alter table slot_team_user drop foreign key FKpugruruole12eeo3hvqpt9s42; -alter table team drop foreign key FK23mky06ol3wc1dj8b11bknntp; -alter table noti drop foreign key FKehey4772h8bhsaix4x6tkrjjc; -alter table game drop foreign key FKjnhlg2dqkrjvaai3e70ymw339; -alter table game drop foreign key FKehwjicpbm71ks5yyuo7co77qj; -alter table game drop foreign key FKgb66of4ini2gvvu76o8pufcr5; -alter table pchange drop foreign key FKqu8jxac7ewvc26oc7hukcixxd; -alter table feedback drop foreign key FK7k33yw505d347mw3avr93akao; -alter table noti drop foreign key FKbjyk0xemxlmv8f6n7nxvx2akk; -alter table pchange drop foreign key FKjld3ge0jy4tjbqxso9wpck9r1; -alter table ranks drop foreign key FK9baj7lwqe9acxbeplowb01mn9; - - -drop table deleted_slot_team_user; -drop table current_match; -drop table event_user; -drop table ping_pong_event; -drop table user_refresh_token; -drop table visit; -#### - -### INT -> BIGINT ### -ALTER TABLE announcement MODIFY id BIGINT NOT NULL AUTO_INCREMENT; -ALTER TABLE feedback MODIFY id BIGINT NOT NULL AUTO_INCREMENT; -ALTER TABLE game MODIFY id BIGINT NOT NULL AUTO_INCREMENT; -ALTER TABLE noti MODIFY id BIGINT NOT NULL AUTO_INCREMENT; -ALTER TABLE pchange MODIFY id BIGINT NOT NULL AUTO_INCREMENT; -ALTER TABLE ranks MODIFY id BIGINT NOT NULL AUTO_INCREMENT; -ALTER TABLE season MODIFY id BIGINT NOT NULL AUTO_INCREMENT; -ALTER TABLE slot_management MODIFY id BIGINT NOT NULL AUTO_INCREMENT; -ALTER TABLE team MODIFY id BIGINT NOT NULL AUTO_INCREMENT; -ALTER TABLE slot_team_user CHANGE COLUMN team_user_id id BIGINT NOT NULL AUTO_INCREMENT; -ALTER TABLE user MODIFY id BIGINT NOT NULL AUTO_INCREMENT; - -### team ### -SET SQL_SAFE_UPDATES=0; -alter table team add column game_id BIGINT; -UPDATE team t - INNER JOIN game g ON g.slot_id = t.slot_id - SET t.game_id = g.id; - -DELETE FROM team -WHERE slot_id NOT IN ( - SELECT slot_id FROM game); - -ALTER TABLE team - ADD CONSTRAINT fk_team_game_game_id - FOREIGN KEY (game_id) REFERENCES game(id) - ON UPDATE CASCADE - ON DELETE CASCADE; - -alter table team modify score INT; -alter table team modify game_id BIGINT not null; -alter table team drop column slot_id; -alter table team drop head_count; -alter table team drop team_ppp; -SET SQL_SAFE_UPDATES=1; -#### - -### team_user ### -alter table slot_team_user modify team_id BIGINT not null; -alter table slot_team_user modify user_id BIGINT not null; -#### - -### announcement ### -SET SQL_SAFE_UPDATES=0; -alter table announcement modify content VARCHAR(1000) not null; -alter table announcement modify creator_intra_id VARCHAR(30) not null; -alter table announcement modify deleter_intra_id VARCHAR(30); -alter table announcement change deleted_time deleted_at DATETIME; -alter table announcement drop column is_del; -alter table announcement change column created_time created_at DATETIME not null; -alter table announcement add column modified_at DATETIME; -update announcement set modified_at=deleted_at where modified_at is null; -SET SQL_SAFE_UPDATES=1; -#### - -### feed_back ### -SET SQL_SAFE_UPDATES=0; -ALTER TABLE feedback CHANGE user_id intra_id VARCHAR(100); -alter table feedback add column user_id BIGINT; - -UPDATE feedback f - INNER JOIN user u -ON f.intra_id = u.intra_id - SET f.user_id = u.id; - -alter table feedback drop intra_id; - -alter table feedback - add constraint fk_feedback_user_user_id - foreign key (user_id) REFERENCES user(id) - ON UPDATE CASCADE; - -ALTER TABLE feedback CHANGE category enum_category INT; -alter table feedback add column category VARCHAR(15) not null; -update feedback set category="BUG" where enum_category=0; -update feedback set category="GAMERESULT" where enum_category=1; -update feedback set category="COMPLAINT" where enum_category=2; -update feedback set category="CHEERS" where enum_category=3; -update feedback set category="OPINION" where enum_category=4; -update feedback set category="ETC" where enum_category=5; -alter table feedback drop enum_category; -SET SQL_SAFE_UPDATES=1; -#### - -### GAME ### -SET SQL_SAFE_UPDATES=0; -alter table game ADD COLUMN start_time DATETIME; -alter table game add column end_time DATETIME; - -alter table game change season season_id bigint not null; - -alter table game - add constraint fk_game_season_season_id - foreign key (season_id) REFERENCES season(id) - ON UPDATE CASCADE; - -ALTER TABLE game CHANGE status enum_status INT; -alter table game add column status VARCHAR(10) not null; -update game set status="LIVE" where enum_status=0; -update game set status="WAIT" where enum_status=1; -update game set status="END" where enum_status=2; -alter table game drop enum_status; - -ALTER TABLE game CHANGE mode enum_mode INT; -alter table game add column mode VARCHAR(10) not null; -update game set mode="NORMAL" where enum_mode=1; -update game set mode="RANK" where enum_mode=2; -alter table game drop column enum_mode; - -UPDATE game g - INNER JOIN slot s ON g.slot_id = s.id - SET g.start_time = s.time, g.end_time = s.end_time; - -alter table game modify start_time DATETIME not null; - -alter table game drop column team1_id; -alter table game drop column team2_id; -alter table game drop column slot_id; -alter table game drop column time; -alter table game drop type; -SET SQL_SAFE_UPDATES=1; -#### - -### NOTI ### -SET SQL_SAFE_UPDATES=0; -ALTER TABLE noti CHANGE user_id intra_id VARCHAR(100); -alter table noti add column user_id BIGINT; - -UPDATE noti n - INNER JOIN user u -ON n.intra_id = u.intra_id - SET n.user_id = u.id; - -alter table noti - add constraint fk_noti_user_user_id - foreign key (user_id) REFERENCES user(id) - ON UPDATE CASCADE; - -ALTER TABLE noti CHANGE noti_type enum_noti_type INT; -alter table noti add column noti_type VARCHAR(15) not null; -update noti set noti_type="MATCHED" where enum_noti_type=0; -update noti set noti_type="CANCELEDBYMAN" where enum_noti_type=1; -update noti set noti_type="CANCELEDBYTIME" where enum_noti_type=2; -update noti set noti_type="IMMINENT" where enum_noti_type=3; -update noti set noti_type="ANNOUNCE" where enum_noti_type=4; -alter table noti drop column enum_noti_type; - -alter table noti drop intra_id; -alter table noti drop slot_id; -delete from noti; -ALTER TABLE noti AUTO_INCREMENT = 1; -SET SQL_SAFE_UPDATES=1; -#### - -### PCHANGE ### -SET SQL_SAFE_UPDATES=0; -ALTER TABLE pchange CHANGE user_id intra_id VARCHAR(100); -alter table pchange add column user_id BIGINT; - -UPDATE pchange p - INNER JOIN user u -ON p.intra_id = u.intra_id - SET p.user_id = u.id; - -alter table pchange modify game_id bigint not null; -alter table pchange - add constraint fk_pchange_user_user_id - foreign key (user_id) REFERENCES user(id) - ON UPDATE CASCADE; - -alter table pchange - add constraint fk_pchange_game_game_id - foreign key (game_id) REFERENCES game(id) - ON UPDATE CASCADE; - -alter table pchange modify user_id BIGINT not null; -alter table pchange modify game_id BIGINT not null; - -alter table pchange drop intra_id; -alter table pchange drop ppp_change; -alter table pchange drop exp_change; -alter table pchange change exp_result exp INT not null; -SET SQL_SAFE_UPDATES=1; -#### - -### RANKS ### -SET SQL_SAFE_UPDATES=0; -ALTER TABLE ranks CHANGE user_id intra_id VARCHAR(100); -alter table ranks add column user_id BIGINT; - -UPDATE ranks r - INNER JOIN user u -ON r.intra_id = u.intra_id - SET r.user_id = u.id; - -alter table ranks modify user_id bigint not null; -alter table ranks - add constraint fk_ranks_user_user_id - foreign key (user_id) REFERENCES user(id) - ON UPDATE CASCADE; - -alter table ranks modify season_id bigint not null; -alter table ranks - add constraint fk_ranks_season_season_id - foreign key (season_id) REFERENCES season(id) - ON UPDATE CASCADE; - -alter table ranks drop intra_id; -alter table ranks drop game_type; -alter table ranks drop racket_type; -#### - -### season ### -alter table season modify season_name VARCHAR(20) not null; -alter table season drop column season_mode; -#### - -### team_user ### -alter table slot_team_user rename to team_user; - -alter table team_user drop created_at; -alter table team_user drop modified_at; -alter table team_user drop slot_id; -#### - -### user ### -ALTER TABLE user CHANGE racket_type enum_racket_type INT; -alter table user add column racket_type VARCHAR(10); -update user set racket_type="PENHOLDER" where enum_racket_type=0; -update user set racket_type="SHAKEHAND" where enum_racket_type=1; -update user set racket_type="DUAL" where enum_racket_type=2; -update user set racket_type="NONE" where enum_racket_type=3; -alter table user drop column enum_racket_type; - -ALTER TABLE user CHANGE role_type enum_role_type INT; -alter table user add column role_type VARCHAR(10); -update user set role_type="ADMIN" where enum_role_type=0; -update user set role_type="USER" where enum_role_type=1; -update user set role_type="USER" where enum_role_type=2; -alter table user drop column enum_role_type; - -alter table user add column kakao_id BIGINT; - -alter table user drop column status_message; -alter table user modify intra_id VARCHAR(30) not null; -alter table user modify e_mail VARCHAR(60); -alter table user modify racket_type VARCHAR(10); -alter table user modify role_type VARCHAR(10) not null; -alter table user modify sns_noti_opt VARCHAR(10); -alter table user drop ppp; - -alter table ranks drop ranking; -#### - -### add Penalty table ### -DROP TABLE IF EXISTS `penalty`; - -CREATE TABLE `penalty` ( - `id` BIGINT NOT NULL AUTO_INCREMENT, - `user_id` BIGINT NOT NULL, - `penalty_type` VARCHAR(20) NOT NULL, - `message` VARCHAR(100) NULL, - `start_time` DATETIME NOT NULL, - `penalty_time` INT NOT NULL, - `created_at` DATETIME NOT NULL, - `modified_at` DATETIME NOT NULL, - PRIMARY KEY (`id`), - INDEX `fk_penalty_user_user_id_idx` (`user_id` ASC) VISIBLE, - CONSTRAINT `fk_penalty_user_user_id` - FOREIGN KEY (`user_id`) - REFERENCES user (`id`) - ON DELETE NO ACTION - ON UPDATE NO ACTION); -#### - -### slot_management ### -alter table slot_management add column start_time DATETIME; -alter table slot_management add column end_time DATETIME; - -SET SQL_SAFE_UPDATES=0; -DELETE t1 -FROM slot_management t1 -JOIN (SELECT MAX(created_at) AS max_created_at FROM slot_management) t2 -WHERE t1.created_at < t2.max_created_at; -SET SQL_SAFE_UPDATES=0; - -UPDATE slot_management -SET start_time = created_at; - -alter table slot_management modify start_time DATETIME NOT NULL; -#### - -### drop tables ### -drop table slot; -#### - -### views ### -create or replace view v_teamuser as -select team.id teamId, team.score, team.win, g.id gameId, g.season_id seasonId, g.start_time startTime, g.status, g.mode, tu.user_id userId, u.intra_id intraId, u.image_uri image, u.total_exp -from team, team_user tu, user u, game g -where team.id=tu.team_id and u.id=tu.user_id and g.id=team.game_id; - -create or replace view v_rank_game_detail as -select team.id teamId, team.score, team.win, g.id gameId, g.season_id seasonId, g.start_time startTime, g.end_time endTime, g.status, g.mode, - tu.user_id userId, u.intra_id intraId, u.image_uri image, u.total_exp, - r.wins, r.losses -from team, team_user tu, user u, game g, ranks r -where team.id=tu.team_id and u.id=tu.user_id and g.id=team.game_id and r.user_id = u.id and r.season_id = g.season_id; -#### \ No newline at end of file diff --git a/src/main/resources/db/migration/V1.2__team_and_teamuser_cascade.sql b/src/main/resources/db/migration/V1.2__team_and_teamuser_cascade.sql deleted file mode 100644 index 3281984c1..000000000 --- a/src/main/resources/db/migration/V1.2__team_and_teamuser_cascade.sql +++ /dev/null @@ -1,19 +0,0 @@ -SET SQL_SAFE_UPDATES=0; - -DELETE FROM team_user -WHERE team_id NOT IN (SELECT id FROM team); -delete FROM game -WHERE id NOT IN (SELECT game_id FROM team); - -SET SQL_SAFE_UPDATES=1; - -alter table team_user -add constraint fk_team_user_team_team_id -foreign key (team_id) REFERENCES team(id) -ON UPDATE CASCADE -ON DELETE CASCADE; - -alter table team_user -add constraint fk_team_user_user_user_id -foreign key (user_id) REFERENCES user(id) -ON UPDATE CASCADE; \ No newline at end of file diff --git a/src/main/resources/db/migration/V3.1__update_tournament_content_column.sql b/src/main/resources/db/migration/V1.2__update_tournament_content_column.sql similarity index 100% rename from src/main/resources/db/migration/V3.1__update_tournament_content_column.sql rename to src/main/resources/db/migration/V1.2__update_tournament_content_column.sql diff --git a/src/main/resources/db/migration/V1.3__add_prevent_delete_season_trigger.sql b/src/main/resources/db/migration/V1.3__add_prevent_delete_season_trigger.sql deleted file mode 100644 index f5f6ef6ee..000000000 --- a/src/main/resources/db/migration/V1.3__add_prevent_delete_season_trigger.sql +++ /dev/null @@ -1,12 +0,0 @@ -DELIMITER // - -CREATE TRIGGER prevent_delete_season -BEFORE DELETE ON season -FOR EACH ROW -BEGIN - IF OLD.start_time < NOW() THEN - SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Cannot delete a Season record with startTime in the past'; - END IF; -END // - -DELIMITER ; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1.4__pchange_add_is_checked_column.sql b/src/main/resources/db/migration/V1.4__pchange_add_is_checked_column.sql deleted file mode 100644 index 47bc6e9bb..000000000 --- a/src/main/resources/db/migration/V1.4__pchange_add_is_checked_column.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE pchange - ADD COLUMN is_checked BIT(1) NOT NULL DEFAULT 0 AFTER user_id; -UPDATE pchange SET is_checked = 1; \ No newline at end of file diff --git a/src/main/resources/db/migration/V1.5__insert_pchange_normal_ppp_result.sql b/src/main/resources/db/migration/V1.5__insert_pchange_normal_ppp_result.sql deleted file mode 100644 index 2fb7d71b2..000000000 --- a/src/main/resources/db/migration/V1.5__insert_pchange_normal_ppp_result.sql +++ /dev/null @@ -1,19 +0,0 @@ -UPDATE pchange p -SET ppp_result = COALESCE( - ( - SELECT subquery.ppp_result - FROM ( - SELECT p2.ppp_result - FROM pchange p2 - INNER JOIN game AS g ON p.game_id = g.id - WHERE p.user_id = p2.user_id - AND g.season_id = (SELECT season_id FROM game WHERE id = p.game_id) - AND p2.created_at < p.created_at - AND p2.ppp_result != 0 - ORDER BY p2.created_at DESC - LIMIT 1 - ) AS subquery - ), - 1000 -) -WHERE ppp_result = 0 OR ppp_result IS NULL; diff --git a/src/main/resources/db/migration/V1__init.sql b/src/main/resources/db/migration/V1__init.sql index e69de29bb..ef00eb70c 100644 --- a/src/main/resources/db/migration/V1__init.sql +++ b/src/main/resources/db/migration/V1__init.sql @@ -0,0 +1,280 @@ +CREATE TABLE `user` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `created_at` datetime NOT NULL, + `modified_at` datetime DEFAULT NULL, + `e_mail` varchar(60) DEFAULT NULL, + `image_uri` varchar(255) DEFAULT NULL, + `intra_id` varchar(30) NOT NULL, + `total_exp` int DEFAULT NULL, + `sns_noti_opt` varchar(10) DEFAULT NULL, + `racket_type` varchar(10) DEFAULT NULL, + `role_type` varchar(10) NOT NULL, + `kakao_id` bigint DEFAULT NULL, + `background` varchar(255) DEFAULT 'BASIC', + `edge` varchar(255) DEFAULT 'BASIC', + `gg_coin` int DEFAULT '0', + `text_color` varchar(10) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `UK_l5220ph2ndjh75g6ya39wy519` (`intra_id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +CREATE TABLE `season` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `end_time` datetime NOT NULL, + `ppp_gap` int NOT NULL, + `season_name` varchar(20) NOT NULL, + `start_ppp` int NOT NULL, + `start_time` datetime NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +CREATE TABLE `tier` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `image_uri` varchar(255) DEFAULT NULL, + `name` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +CREATE TABLE `announcement` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `content` varchar(1000) NOT NULL, + `creator_intra_id` varchar(30) NOT NULL, + `created_at` datetime NOT NULL, + `deleter_intra_id` varchar(30) DEFAULT NULL, + `deleted_at` datetime DEFAULT NULL, + `modified_at` datetime DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +CREATE TABLE `coin_history` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `amount` int DEFAULT NULL, + `created_at` datetime(6) NOT NULL, + `history` varchar(30) DEFAULT NULL, + `user_id` bigint DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `user_id` (`user_id`), + CONSTRAINT `coin_history_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +CREATE TABLE `coin_policy` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `user_id` bigint DEFAULT NULL, + `attendance` int DEFAULT NULL, + `created_at` datetime(6) NOT NULL, + `normal` int DEFAULT NULL, + `rank_lose` int DEFAULT NULL, + `rank_win` int DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `fk_coin_policy_user_user_id` (`user_id`), + CONSTRAINT `fk_coin_policy_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +CREATE TABLE `feedback` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `created_at` datetime NOT NULL, + `modified_at` datetime DEFAULT NULL, + `content` varchar(600) NOT NULL, + `is_solved` bit(1) NOT NULL, + `user_id` bigint DEFAULT NULL, + `category` varchar(15) NOT NULL, + PRIMARY KEY (`id`), + KEY `fk_feedback_user_user_id` (`user_id`), + CONSTRAINT `fk_feedback_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +CREATE TABLE `game` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `season_id` bigint NOT NULL, + `start_time` datetime NOT NULL, + `end_time` datetime DEFAULT NULL, + `status` varchar(10) NOT NULL, + `mode` varchar(10) NOT NULL, + PRIMARY KEY (`id`), + KEY `fk_game_season_season_id` (`season_id`), + CONSTRAINT `fk_game_season_season_id` FOREIGN KEY (`season_id`) REFERENCES `season` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +CREATE TABLE `item` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `created_at` datetime(6) NOT NULL, + `discount` int DEFAULT NULL, + `image_uri` varchar(255) DEFAULT NULL, + `is_visible` bit(1) NOT NULL, + `name` varchar(30) DEFAULT NULL, + `price` int NOT NULL, + `creator_intra_id` varchar(10) NOT NULL, + `deleter_intra_id` varchar(10) DEFAULT NULL, + `type` varchar(255) NOT NULL, + `main_content` varchar(255) DEFAULT NULL, + `sub_content` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +CREATE TABLE `receipt` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `owner_intra_id` varchar(255) NOT NULL, + `created_at` datetime(6) NOT NULL, + `purchaser_intra_id` varchar(255) NOT NULL, + `status` varchar(255) NOT NULL, + `item_id` bigint NOT NULL, + PRIMARY KEY (`id`), + KEY `fk_receipt_item_item_id` (`item_id`), + CONSTRAINT `fk_receipt_item_item_id` FOREIGN KEY (`item_id`) REFERENCES `item` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + + +CREATE TABLE `megaphone` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `content` varchar(30) DEFAULT NULL, + `used_at` date NOT NULL, + `user_id` bigint NOT NULL, + `receipt_id` bigint DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `fk_megaphone_user_user_id` (`user_id`), + KEY `fk_megaphone_receipt_receipt_id` (`receipt_id`), + CONSTRAINT `fk_megaphone_receipt_receipt_id` FOREIGN KEY (`receipt_id`) REFERENCES `receipt` (`id`), + CONSTRAINT `fk_megaphone_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +CREATE TABLE `noti` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `created_at` datetime NOT NULL, + `modified_at` datetime DEFAULT NULL, + `is_checked` bit(1) NOT NULL, + `message` varchar(255) DEFAULT NULL, + `user_id` bigint DEFAULT NULL, + `noti_type` varchar(15) NOT NULL, + PRIMARY KEY (`id`), + KEY `fk_noti_user_user_id` (`user_id`), + CONSTRAINT `fk_noti_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +CREATE TABLE `pchange` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `created_at` datetime NOT NULL, + `modified_at` datetime DEFAULT NULL, + `ppp_result` int NOT NULL, + `game_id` bigint NOT NULL, + `exp` int NOT NULL, + `user_id` bigint NOT NULL, + `is_checked` bit(1) NOT NULL DEFAULT b'0', + PRIMARY KEY (`id`), + KEY `fk_pchange_user_user_id` (`user_id`), + KEY `fk_pchange_game_game_id` (`game_id`), + CONSTRAINT `fk_pchange_game_game_id` FOREIGN KEY (`game_id`) REFERENCES `game` (`id`) ON UPDATE CASCADE, + CONSTRAINT `fk_pchange_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +CREATE TABLE `penalty` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `user_id` bigint NOT NULL, + `penalty_type` varchar(20) NOT NULL, + `message` varchar(100) DEFAULT NULL, + `start_time` datetime NOT NULL, + `penalty_time` int NOT NULL, + `created_at` datetime NOT NULL, + `modified_at` datetime NOT NULL, + PRIMARY KEY (`id`), + KEY `fk_penalty_user_user_id_idx` (`user_id`), + CONSTRAINT `fk_penalty_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +CREATE TABLE `ranks` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `created_at` datetime NOT NULL, + `modified_at` datetime DEFAULT NULL, + `losses` int NOT NULL, + `ppp` int NOT NULL, + `season_id` bigint NOT NULL, + `wins` int NOT NULL, + `status_message` varchar(255) DEFAULT NULL, + `user_id` bigint NOT NULL, + `tier_id` bigint DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `fk_ranks_user_user_id` (`user_id`), + KEY `fk_ranks_season_season_id` (`season_id`), + KEY `fk_ranks_tier_tier_id` (`tier_id`), + CONSTRAINT `fk_ranks_season_season_id` FOREIGN KEY (`season_id`) REFERENCES `season` (`id`) ON UPDATE CASCADE, + CONSTRAINT `fk_ranks_tier_tier_id` FOREIGN KEY (`tier_id`) REFERENCES `tier` (`id`), + CONSTRAINT `fk_ranks_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +CREATE TABLE `slot_management` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `created_at` datetime NOT NULL, + `modified_at` datetime DEFAULT NULL, + `future_slot_time` int NOT NULL, + `game_interval` int NOT NULL, + `open_minute` int NOT NULL, + `past_slot_time` int NOT NULL, + `start_time` datetime NOT NULL, + `end_time` datetime DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +CREATE TABLE `team` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `score` int DEFAULT NULL, + `win` bit(1) DEFAULT NULL, + `game_id` bigint NOT NULL, + PRIMARY KEY (`id`), + KEY `fk_team_game_game_id` (`game_id`), + CONSTRAINT `fk_team_game_game_id` FOREIGN KEY (`game_id`) REFERENCES `game` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +CREATE TABLE `team_user` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `team_id` bigint NOT NULL, + `user_id` bigint NOT NULL, + PRIMARY KEY (`id`), + KEY `fk_team_user_team_team_id` (`team_id`), + KEY `fk_team_user_user_user_id` (`user_id`), + CONSTRAINT `fk_team_user_team_team_id` FOREIGN KEY (`team_id`) REFERENCES `team` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `fk_team_user_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +CREATE TABLE `user_image` ( + `id` bigint NOT NULL AUTO_INCREMENT, + `user_id` bigint DEFAULT NULL, + `image_uri` varchar(255) DEFAULT NULL, + `created_at` datetime(6) NOT NULL, + `deleted_at` datetime(6) DEFAULT NULL, + `is_current` bit(1) NOT NULL DEFAULT b'1', + PRIMARY KEY (`id`), + KEY `fk_user_image_user_user_id` (`user_id`), + CONSTRAINT `fk_user_image_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; + + +create or replace view v_teamuser as +select team.id teamId, team.score, team.win, g.id gameId, g.season_id seasonId, g.start_time startTime, g.status, g.mode, tu.user_id userId, u.intra_id intraId, u.image_uri image, u.total_exp +from team, team_user tu, user u, game g +where team.id=tu.team_id and u.id=tu.user_id and g.id=team.game_id; + + +create or replace view v_rank_game_detail as +select team.id teamId, team.score, team.win, g.id gameId, g.season_id seasonId, g.start_time startTime, g.end_time endTime, g.status, g.mode, + tu.user_id userId, u.intra_id intraId, u.image_uri image, u.total_exp, + r.wins, r.losses +from team, team_user tu, user u, game g, ranks r +where team.id=tu.team_id and u.id=tu.user_id and g.id=team.game_id and r.user_id = u.id and r.season_id = g.season_id; + diff --git a/src/main/resources/db/migration/V2.1__add_item_creator.sql b/src/main/resources/db/migration/V2.1__add_item_creator.sql deleted file mode 100644 index 0d0c75c10..000000000 --- a/src/main/resources/db/migration/V2.1__add_item_creator.sql +++ /dev/null @@ -1,5 +0,0 @@ -alter table item - add column creator_intra_id varchar(10) NOT NULL; - -alter table item - add column deleter_intra_id varchar(10); diff --git a/src/main/resources/db/migration/V2.2__add_item_type.sql b/src/main/resources/db/migration/V2.2__add_item_type.sql deleted file mode 100644 index d1a0ed5ca..000000000 --- a/src/main/resources/db/migration/V2.2__add_item_type.sql +++ /dev/null @@ -1,2 +0,0 @@ -alter table item - add column type varchar(255) NOT NULL; \ No newline at end of file diff --git a/src/main/resources/db/migration/V2.3__add_megaphone_receiptId.sql b/src/main/resources/db/migration/V2.3__add_megaphone_receiptId.sql deleted file mode 100644 index e740d7362..000000000 --- a/src/main/resources/db/migration/V2.3__add_megaphone_receiptId.sql +++ /dev/null @@ -1,7 +0,0 @@ -alter table megaphone - add column receipt_id bigint; - -alter table megaphone - add constraint fk_megaphone_receipt_receipt_id - foreign key (receipt_id) - references receipt (id); \ No newline at end of file diff --git a/src/main/resources/db/migration/V2.4__modify_item_content_columns.sql b/src/main/resources/db/migration/V2.4__modify_item_content_columns.sql deleted file mode 100644 index 06d2baae0..000000000 --- a/src/main/resources/db/migration/V2.4__modify_item_content_columns.sql +++ /dev/null @@ -1,10 +0,0 @@ -alter table item - add column main_content varchar(255); - -alter table item - add column sub_content varchar(255); - -UPDATE item SET main_content = content, sub_content = content; - -alter table item -drop column content; \ No newline at end of file diff --git a/src/main/resources/db/migration/V2.5__add_userImage_and_user_image_uri.sql b/src/main/resources/db/migration/V2.5__add_userImage_and_user_image_uri.sql deleted file mode 100644 index c67b74395..000000000 --- a/src/main/resources/db/migration/V2.5__add_userImage_and_user_image_uri.sql +++ /dev/null @@ -1,18 +0,0 @@ -create table user_image -( - id bigint not null auto_increment, - user_id bigint, - image_uri varchar(255), - created_at datetime(6) not null, - deleted_at datetime(6) default null, - is_current bit default 1 not null, - - primary key (id) -); - -alter table user_image - add constraint fk_user_image_user_user_id - foreign key (user_id) - references `user` (id); - -INSERT INTO user_image (user_id, image_uri, created_at) SELECT id, image_uri, created_at FROM user; \ No newline at end of file diff --git a/src/main/resources/db/migration/V2__migration_42gg_4th.sql b/src/main/resources/db/migration/V2__migration_42gg_4th.sql deleted file mode 100644 index 04c56121c..000000000 --- a/src/main/resources/db/migration/V2__migration_42gg_4th.sql +++ /dev/null @@ -1,102 +0,0 @@ -create table coin_history -( - id bigint not null auto_increment, - amount integer, - created_at datetime(6) not null, - history varchar(30), - user_id bigint, - primary key (id) -); - -create table coin_policy -( - id bigint not null auto_increment, - user_id bigint, - attendance integer, - created_at datetime(6) not null, - normal integer, - rank_lose integer, - rank_win integer, - primary key (id) -); - -create table item -( - id bigint not null auto_increment, - content varchar(255), - created_at datetime(6) not null, - discount integer, - image_uri varchar(255), - is_visible bit not null, - name varchar(30), - price integer not null, - primary key (id) -); - -create table megaphone -( - id bigint not null auto_increment, - content varchar(30), - used_at date not null, - user_id bigint not null, - primary key (id) -); - -alter table ranks - add column tier_id bigint; - -create table receipt -( - id bigint not null auto_increment, - owner_intra_id varchar(255) not null, - created_at datetime(6) not null, - purchaser_intra_id varchar(255) not null, - status varchar(255) not null, - item_id bigint not null, - primary key (id) -); - -create table tier -( - id bigint not null auto_increment, - image_uri varchar(255), - name varchar(255), - primary key (id) -); - -alter table user - add column background varchar(255) default "BASIC"; - -alter table user - add column edge varchar(255) default "BASIC"; - -alter table user - add column gg_coin integer default 0; - -alter table user - add column text_color varchar(10); - -alter table coin_history - add constraint fk_coin_history_user_user_id - foreign key (user_id) - references user (id); - -alter table coin_policy - add constraint fk_coin_policy_user_user_id - foreign key (user_id) - references user (id); - -alter table megaphone - add constraint fk_megaphone_user_user_id - foreign key (user_id) - references user (id); - -alter table ranks - add constraint fk_ranks_tier_tier_id - foreign key (tier_id) - references tier (id); - -alter table receipt - add constraint fk_receipt_item_item_id - foreign key (item_id) - references item (id); \ No newline at end of file From bed6010103b2d3d218e620d3ee91773f60e4eefb Mon Sep 17 00:00:00 2001 From: middlefitting Date: Wed, 10 Jan 2024 16:24:29 +0900 Subject: [PATCH 2/5] =?UTF-8?q?ci:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20schema.?= =?UTF-8?q?sql=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/schema.sql | 352 ---------------------------------- 1 file changed, 352 deletions(-) delete mode 100644 src/test/resources/schema.sql diff --git a/src/test/resources/schema.sql b/src/test/resources/schema.sql deleted file mode 100644 index 975657742..000000000 --- a/src/test/resources/schema.sql +++ /dev/null @@ -1,352 +0,0 @@ -SET FOREIGN_KEY_CHECKS=0; - -DROP TABLE IF EXISTS `user`; -CREATE TABLE `user` ( -`id` bigint NOT NULL AUTO_INCREMENT, -`created_at` datetime NOT NULL, -`modified_at` datetime DEFAULT NULL, -`e_mail` varchar(60) DEFAULT NULL, -`image_uri` varchar(255) DEFAULT NULL, -`intra_id` varchar(30) NOT NULL, -`total_exp` int DEFAULT NULL, -`sns_noti_opt` varchar(10) DEFAULT NULL, -`racket_type` varchar(10) DEFAULT NULL, -`role_type` varchar(10) NOT NULL, -`kakao_id` bigint DEFAULT NULL, -`background` varchar(255) DEFAULT 'BASIC', -`edge` varchar(255) DEFAULT 'BASIC', -`gg_coin` int DEFAULT '0', -`text_color` varchar(10) DEFAULT NULL, -PRIMARY KEY (`id`), -UNIQUE KEY `UK_l5220ph2ndjh75g6ya39wy519` (`intra_id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `season`; -CREATE TABLE `season` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `end_time` datetime NOT NULL, - `ppp_gap` int NOT NULL, - `season_name` varchar(20) NOT NULL, - `start_ppp` int NOT NULL, - `start_time` datetime NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `tier`; -CREATE TABLE `tier` ( -`id` bigint NOT NULL AUTO_INCREMENT, -`image_uri` varchar(255) DEFAULT NULL, -`name` varchar(255) DEFAULT NULL, -PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `announcement`; -CREATE TABLE `announcement` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `content` varchar(1000) NOT NULL, - `creator_intra_id` varchar(30) NOT NULL, - `created_at` datetime NOT NULL, - `deleter_intra_id` varchar(30) DEFAULT NULL, - `deleted_at` datetime DEFAULT NULL, - `modified_at` datetime DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `coin_history`; -CREATE TABLE `coin_history` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `amount` int DEFAULT NULL, - `created_at` datetime(6) NOT NULL, - `history` varchar(30) DEFAULT NULL, - `user_id` bigint DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `user_id` (`user_id`), - CONSTRAINT `coin_history_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `coin_policy`; -CREATE TABLE `coin_policy` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `user_id` bigint DEFAULT NULL, - `attendance` int DEFAULT NULL, - `created_at` datetime(6) NOT NULL, - `normal` int DEFAULT NULL, - `rank_lose` int DEFAULT NULL, - `rank_win` int DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `fk_coin_policy_user_user_id` (`user_id`), - CONSTRAINT `fk_coin_policy_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `feedback`; -CREATE TABLE `feedback` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `created_at` datetime NOT NULL, - `modified_at` datetime DEFAULT NULL, - `content` varchar(600) NOT NULL, - `is_solved` bit(1) NOT NULL, - `user_id` bigint DEFAULT NULL, - `category` varchar(15) NOT NULL, - PRIMARY KEY (`id`), - KEY `fk_feedback_user_user_id` (`user_id`), - CONSTRAINT `fk_feedback_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `game`; -CREATE TABLE `game` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `season_id` bigint NOT NULL, - `start_time` datetime NOT NULL, - `end_time` datetime DEFAULT NULL, - `status` varchar(10) NOT NULL, - `mode` varchar(10) NOT NULL, - PRIMARY KEY (`id`), - KEY `fk_game_season_season_id` (`season_id`), - CONSTRAINT `fk_game_season_season_id` FOREIGN KEY (`season_id`) REFERENCES `season` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `item`; -CREATE TABLE `item` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `created_at` datetime(6) NOT NULL, - `discount` int DEFAULT NULL, - `image_uri` varchar(255) DEFAULT NULL, - `is_visible` bit(1) NOT NULL, - `name` varchar(30) DEFAULT NULL, - `price` int NOT NULL, - `creator_intra_id` varchar(10) NOT NULL, - `deleter_intra_id` varchar(10) DEFAULT NULL, - `type` varchar(255) NOT NULL, - `main_content` varchar(255) DEFAULT NULL, - `sub_content` varchar(255) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `receipt`; -CREATE TABLE `receipt` ( -`id` bigint NOT NULL AUTO_INCREMENT, -`owner_intra_id` varchar(255) NOT NULL, -`created_at` datetime(6) NOT NULL, -`purchaser_intra_id` varchar(255) NOT NULL, -`status` varchar(255) NOT NULL, -`item_id` bigint NOT NULL, -PRIMARY KEY (`id`), -KEY `fk_receipt_item_item_id` (`item_id`), -CONSTRAINT `fk_receipt_item_item_id` FOREIGN KEY (`item_id`) REFERENCES `item` (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - - -DROP TABLE IF EXISTS `megaphone`; -CREATE TABLE `megaphone` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `content` varchar(30) DEFAULT NULL, - `used_at` date NOT NULL, - `user_id` bigint NOT NULL, - `receipt_id` bigint DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `fk_megaphone_user_user_id` (`user_id`), - KEY `fk_megaphone_receipt_receipt_id` (`receipt_id`), - CONSTRAINT `fk_megaphone_receipt_receipt_id` FOREIGN KEY (`receipt_id`) REFERENCES `receipt` (`id`), - CONSTRAINT `fk_megaphone_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `noti`; -CREATE TABLE `noti` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `created_at` datetime NOT NULL, - `modified_at` datetime DEFAULT NULL, - `is_checked` bit(1) NOT NULL, - `message` varchar(255) DEFAULT NULL, - `user_id` bigint DEFAULT NULL, - `noti_type` varchar(15) NOT NULL, - PRIMARY KEY (`id`), - KEY `fk_noti_user_user_id` (`user_id`), - CONSTRAINT `fk_noti_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `pchange`; -CREATE TABLE `pchange` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `created_at` datetime NOT NULL, - `modified_at` datetime DEFAULT NULL, - `ppp_result` int NOT NULL, - `game_id` bigint NOT NULL, - `exp` int NOT NULL, - `user_id` bigint NOT NULL, - `is_checked` bit(1) NOT NULL DEFAULT b'0', - PRIMARY KEY (`id`), - KEY `fk_pchange_user_user_id` (`user_id`), - KEY `fk_pchange_game_game_id` (`game_id`), - CONSTRAINT `fk_pchange_game_game_id` FOREIGN KEY (`game_id`) REFERENCES `game` (`id`) ON UPDATE CASCADE, - CONSTRAINT `fk_pchange_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `penalty`; -CREATE TABLE `penalty` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `user_id` bigint NOT NULL, - `penalty_type` varchar(20) NOT NULL, - `message` varchar(100) DEFAULT NULL, - `start_time` datetime NOT NULL, - `penalty_time` int NOT NULL, - `created_at` datetime NOT NULL, - `modified_at` datetime NOT NULL, - PRIMARY KEY (`id`), - KEY `fk_penalty_user_user_id_idx` (`user_id`), - CONSTRAINT `fk_penalty_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `ranks`; -CREATE TABLE `ranks` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `created_at` datetime NOT NULL, - `modified_at` datetime DEFAULT NULL, - `losses` int NOT NULL, - `ppp` int NOT NULL, - `season_id` bigint NOT NULL, - `wins` int NOT NULL, - `status_message` varchar(255) DEFAULT NULL, - `user_id` bigint NOT NULL, - `tier_id` bigint DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `fk_ranks_user_user_id` (`user_id`), - KEY `fk_ranks_season_season_id` (`season_id`), - KEY `fk_ranks_tier_tier_id` (`tier_id`), - CONSTRAINT `fk_ranks_season_season_id` FOREIGN KEY (`season_id`) REFERENCES `season` (`id`) ON UPDATE CASCADE, - CONSTRAINT `fk_ranks_tier_tier_id` FOREIGN KEY (`tier_id`) REFERENCES `tier` (`id`), - CONSTRAINT `fk_ranks_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `slot_management`; -CREATE TABLE `slot_management` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `created_at` datetime NOT NULL, - `modified_at` datetime DEFAULT NULL, - `future_slot_time` int NOT NULL, - `game_interval` int NOT NULL, - `open_minute` int NOT NULL, - `past_slot_time` int NOT NULL, - `start_time` datetime NOT NULL, - `end_time` datetime DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `team`; -CREATE TABLE `team` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `score` int DEFAULT NULL, - `win` bit(1) DEFAULT NULL, - `game_id` bigint NOT NULL, - PRIMARY KEY (`id`), - KEY `fk_team_game_game_id` (`game_id`), - CONSTRAINT `fk_team_game_game_id` FOREIGN KEY (`game_id`) REFERENCES `game` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `team_user`; -CREATE TABLE `team_user` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `team_id` bigint NOT NULL, - `user_id` bigint NOT NULL, - PRIMARY KEY (`id`), - KEY `fk_team_user_team_team_id` (`team_id`), - KEY `fk_team_user_user_user_id` (`user_id`), - CONSTRAINT `fk_team_user_team_team_id` FOREIGN KEY (`team_id`) REFERENCES `team` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `fk_team_user_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `tournament`; -CREATE TABLE tournament ( - id BIGINT NOT NULL AUTO_INCREMENT, - title VARCHAR(30) NOT NULL, - contents VARCHAR(1000) NOT NULL, - start_time DATETIME NOT NULL, - end_time DATETIME NOT NULL, - type VARCHAR(15) NOT NULL, - status VARCHAR(10) NOT NULL DEFAULT 'BEFORE', - created_at DATETIME NOT NULL, - modified_at DATETIME NOT NULL, - winner_id BIGINT, - PRIMARY KEY (id), - FOREIGN KEY (winner_id) REFERENCES user(id) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `tournament_user`; -CREATE TABLE tournament_user ( - id BIGINT NOT NULL AUTO_INCREMENT, - user_id BIGINT NOT NULL, - tournament_id BIGINT NOT NULL, - is_joined BOOLEAN NOT NULL DEFAULT FALSE, - register_time DATETIME NOT NULL, - created_at DATETIME NOT NULL, - modified_at DATETIME NOT NULL, - PRIMARY KEY (id), - FOREIGN KEY (tournament_id) REFERENCES tournament(id) - ON UPDATE CASCADE - ON DELETE CASCADE , - FOREIGN KEY (user_id) REFERENCES user(id) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `tournament_game`; -CREATE TABLE tournament_game ( - id BIGINT NOT NULL AUTO_INCREMENT, - tournament_id BIGINT NOT NULL, - game_id BIGINT, - round VARCHAR(20) NOT NULL, - created_at DATETIME NOT NULL, - modified_at DATETIME NOT NULL, - PRIMARY KEY (id), - FOREIGN KEY (tournament_id) REFERENCES tournament(id) - ON UPDATE CASCADE - ON DELETE CASCADE , - FOREIGN KEY (game_id) REFERENCES game(id) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -DROP TABLE IF EXISTS `user_image`; -CREATE TABLE `user_image` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `user_id` bigint DEFAULT NULL, - `image_uri` varchar(255) DEFAULT NULL, - `created_at` datetime(6) NOT NULL, - `deleted_at` datetime(6) DEFAULT NULL, - `is_current` bit(1) NOT NULL DEFAULT b'1', - PRIMARY KEY (`id`), - KEY `fk_user_image_user_user_id` (`user_id`), - CONSTRAINT `fk_user_image_user_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; - - -create or replace view v_teamuser as -select team.id teamId, team.score, team.win, g.id gameId, g.season_id seasonId, g.start_time startTime, g.status, g.mode, tu.user_id userId, u.intra_id intraId, u.image_uri image, u.total_exp -from team, team_user tu, user u, game g -where team.id=tu.team_id and u.id=tu.user_id and g.id=team.game_id; - - -create or replace view v_rank_game_detail as -select team.id teamId, team.score, team.win, g.id gameId, g.season_id seasonId, g.start_time startTime, g.end_time endTime, g.status, g.mode, - tu.user_id userId, u.intra_id intraId, u.image_uri image, u.total_exp, - r.wins, r.losses -from team, team_user tu, user u, game g, ranks r -where team.id=tu.team_id and u.id=tu.user_id and g.id=team.game_id and r.user_id = u.id and r.season_id = g.season_id; - -SET FOREIGN_KEY_CHECKS=1; \ No newline at end of file From dd229c412f13b3d0b16a7abeb9498a004650b2d3 Mon Sep 17 00:00:00 2001 From: middlefitting Date: Wed, 10 Jan 2024 16:26:58 +0900 Subject: [PATCH 3/5] feat: mysql tc context --- .../server/utils/config/MySQLInitializer.java | 39 +++++++++++++++++++ src/test/resources/application.yml | 20 +++------- 2 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 src/test/java/com/gg/server/utils/config/MySQLInitializer.java diff --git a/src/test/java/com/gg/server/utils/config/MySQLInitializer.java b/src/test/java/com/gg/server/utils/config/MySQLInitializer.java new file mode 100644 index 000000000..1f4fde72e --- /dev/null +++ b/src/test/java/com/gg/server/utils/config/MySQLInitializer.java @@ -0,0 +1,39 @@ +package com.gg.server.utils.config; + +import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.testcontainers.containers.MySQLContainer; + +/** + * MysqlInitializer. + * + *

+ * mysql testContainer 초기화 작업을 수행 + *

+ * + * @author : middlefitting + * @since : 2024/01/09 + */ +public class MySQLInitializer implements + ApplicationContextInitializer { + private static final String params = "?serverTimezone=Asia/Seoul&characterEncoding=UTF-8"; + private static final MySQLContainer MYSQL_CONTAINER = + new MySQLContainer<>("mysql:8.0") + .withDatabaseName("test") + .withUsername("root") + .withPassword("1234"); + + static { + MYSQL_CONTAINER.start(); + } + + @Override + public void initialize(ConfigurableApplicationContext applicationContext) { + TestPropertyValues.of( + "spring.datasource.url=" + MYSQL_CONTAINER.getJdbcUrl() + params, + "spring.datasource.username=" + MYSQL_CONTAINER.getUsername(), + "spring.datasource.password=" + MYSQL_CONTAINER.getPassword() + ).applyTo(applicationContext.getEnvironment()); + } +} diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index eea2fa9f1..3cbe9fdc1 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -3,7 +3,7 @@ spring: name: 42gg profiles: - active: local + active: testCode security: oauth2.client: @@ -109,28 +109,21 @@ server: enabled: true --- -spring.config.activate.on-profile: local +spring.config.activate.on-profile: testCode # =========================== LOCAL =========================== spring: - datasource: - driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver - url: jdbc:tc:mysql:8.0:///testdb?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 - username: root - password: 1234 - flyway: - enabled: false + enabled: true baselineOnMigrate: true - locations: classpath:db/migration/test - url: jdbc:tc:mysql:8.0:///testdb?serverTimezone=Asia/Seoul&characterEncoding=UTF-8 + locations: classpath:db/migration user: root password: 1234 jpa: database-platform: org.hibernate.dialect.MySQL8Dialect hibernate: - ddl-auto: validate + ddl-auto: none properties: hibernate: show_sql: true @@ -151,9 +144,6 @@ spring: # Redis 설정 cache: type: redis - sql: - init: - mode: always # cors 설정 cors: From 99c4dcabeb554bcb2af49fcf12f688882839574f Mon Sep 17 00:00:00 2001 From: middlefitting Date: Wed, 10 Jan 2024 16:27:25 +0900 Subject: [PATCH 4/5] =?UTF-8?q?update:=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BB=A4=EC=8A=A4=ED=85=80=20=EC=95=A0=EB=85=B8=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EC=85=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gg/server/utils/annotation/IntegrationTest.java | 8 ++++---- .../annotation/IntegrationTestWithRedisTransaction.java | 5 +++-- .../annotation/{TestType.java => TestTypeConstant.java} | 6 +++++- .../java/com/gg/server/utils/annotation/UnitTest.java | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) rename src/test/java/com/gg/server/utils/annotation/{TestType.java => TestTypeConstant.java} (64%) diff --git a/src/test/java/com/gg/server/utils/annotation/IntegrationTest.java b/src/test/java/com/gg/server/utils/annotation/IntegrationTest.java index 8c20cdc73..b21fdaddd 100644 --- a/src/test/java/com/gg/server/utils/annotation/IntegrationTest.java +++ b/src/test/java/com/gg/server/utils/annotation/IntegrationTest.java @@ -1,5 +1,6 @@ package com.gg.server.utils.annotation; +import com.gg.server.utils.config.MySQLInitializer; import com.gg.server.utils.config.RedisInitializer; import com.gg.server.utils.config.TestRedisConfig; import java.lang.annotation.ElementType; @@ -15,16 +16,15 @@ * 통합테스트 환경의 의존성 관리를 위한 어노테이션. * *

- * 기본적으로 redis 트랜잭션을 false로 처리하는 설정을 Import 한다. + * 기본적으로 redis 트랜잭션을 false로 처리하는 설정을 Import 한다. *

- * */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @SpringBootTest @Import(TestRedisConfig.class) -@ContextConfiguration(initializers = RedisInitializer.class) -@Tag(TestType.INTEGRATION_TEST) +@ContextConfiguration(initializers = {RedisInitializer.class, MySQLInitializer.class}) +@Tag(TestTypeConstant.INTEGRATION_TEST) public @interface IntegrationTest { } \ No newline at end of file diff --git a/src/test/java/com/gg/server/utils/annotation/IntegrationTestWithRedisTransaction.java b/src/test/java/com/gg/server/utils/annotation/IntegrationTestWithRedisTransaction.java index ad3d39d1f..5a2a0b5f9 100644 --- a/src/test/java/com/gg/server/utils/annotation/IntegrationTestWithRedisTransaction.java +++ b/src/test/java/com/gg/server/utils/annotation/IntegrationTestWithRedisTransaction.java @@ -1,5 +1,6 @@ package com.gg.server.utils.annotation; +import com.gg.server.utils.config.MySQLInitializer; import com.gg.server.utils.config.RedisInitializer; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -20,8 +21,8 @@ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @SpringBootTest -@ContextConfiguration(initializers = RedisInitializer.class) -@Tag(TestType.INTEGRATION_TEST) +@ContextConfiguration(initializers = {RedisInitializer.class, MySQLInitializer.class}) +@Tag(TestTypeConstant.INTEGRATION_TEST) public @interface IntegrationTestWithRedisTransaction { } \ No newline at end of file diff --git a/src/test/java/com/gg/server/utils/annotation/TestType.java b/src/test/java/com/gg/server/utils/annotation/TestTypeConstant.java similarity index 64% rename from src/test/java/com/gg/server/utils/annotation/TestType.java rename to src/test/java/com/gg/server/utils/annotation/TestTypeConstant.java index 2fef11223..c0d89cc16 100644 --- a/src/test/java/com/gg/server/utils/annotation/TestType.java +++ b/src/test/java/com/gg/server/utils/annotation/TestTypeConstant.java @@ -1,5 +1,8 @@ package com.gg.server.utils.annotation; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + /** * TestType. * @@ -8,7 +11,8 @@ *

* */ -public class TestType { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class TestTypeConstant { public static final String UNIT_TEST = "UnitTest"; public static final String INTEGRATION_TEST = "IntegrationTest"; } diff --git a/src/test/java/com/gg/server/utils/annotation/UnitTest.java b/src/test/java/com/gg/server/utils/annotation/UnitTest.java index 2bb136144..9a2dd50df 100644 --- a/src/test/java/com/gg/server/utils/annotation/UnitTest.java +++ b/src/test/java/com/gg/server/utils/annotation/UnitTest.java @@ -12,7 +12,7 @@ */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) -@Tag(TestType.UNIT_TEST) +@Tag(TestTypeConstant.UNIT_TEST) public @interface UnitTest { } \ No newline at end of file From e58dc930e064d8d0b31cefe1ad4c63956beaa8a0 Mon Sep 17 00:00:00 2001 From: middlefitting Date: Wed, 10 Jan 2024 16:29:52 +0900 Subject: [PATCH 5/5] update: ddl validate --- src/test/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 3cbe9fdc1..4bad41a72 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -123,7 +123,7 @@ spring: jpa: database-platform: org.hibernate.dialect.MySQL8Dialect hibernate: - ddl-auto: none + ddl-auto: validate properties: hibernate: show_sql: true