From 947fe620c98475e219962b4b93bba62d1114c3f7 Mon Sep 17 00:00:00 2001 From: jihukimme Date: Mon, 8 Sep 2025 14:51:34 +0900 Subject: [PATCH 01/10] =?UTF-8?q?refactor:=20DTO=20=EB=84=A4=EC=9D=B4?= =?UTF-8?q?=EB=B0=8D=EC=9D=84=20=EB=8B=A8=EC=88=98=ED=98=95=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...partmentsCardDto.java => DepartmentCardDo.java} | 2 +- .../controller/OrganizationController.java | 4 ++-- ...nOptionsDto.java => OrganizationOptionDto.java} | 10 +++++----- .../organization/service/OrganizationService.java | 14 +++++++------- .../dto/{RolesCardDto.java => RoleCardDto.java} | 2 +- .../icebang/mapper/OrganizationMapper.java | 8 ++++---- .../mybatis/mapper/OrganizationMapper.xml | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) rename apps/user-service/src/main/java/com/gltkorea/icebang/domain/department/dto/{DepartmentsCardDto.java => DepartmentCardDo.java} (87%) rename apps/user-service/src/main/java/com/gltkorea/icebang/domain/organization/dto/{OrganizationOptionsDto.java => OrganizationOptionDto.java} (55%) rename apps/user-service/src/main/java/com/gltkorea/icebang/domain/roles/dto/{RolesCardDto.java => RoleCardDto.java} (92%) diff --git a/apps/user-service/src/main/java/com/gltkorea/icebang/domain/department/dto/DepartmentsCardDto.java b/apps/user-service/src/main/java/com/gltkorea/icebang/domain/department/dto/DepartmentCardDo.java similarity index 87% rename from apps/user-service/src/main/java/com/gltkorea/icebang/domain/department/dto/DepartmentsCardDto.java rename to apps/user-service/src/main/java/com/gltkorea/icebang/domain/department/dto/DepartmentCardDo.java index 5f50fabd..e891e966 100644 --- a/apps/user-service/src/main/java/com/gltkorea/icebang/domain/department/dto/DepartmentsCardDto.java +++ b/apps/user-service/src/main/java/com/gltkorea/icebang/domain/department/dto/DepartmentCardDo.java @@ -9,7 +9,7 @@ @Data @Builder @AllArgsConstructor -public class DepartmentsCardDto { +public class DepartmentCardDo { private BigInteger id; private String name; } diff --git a/apps/user-service/src/main/java/com/gltkorea/icebang/domain/organization/controller/OrganizationController.java b/apps/user-service/src/main/java/com/gltkorea/icebang/domain/organization/controller/OrganizationController.java index ff3567b9..7375fcbe 100644 --- a/apps/user-service/src/main/java/com/gltkorea/icebang/domain/organization/controller/OrganizationController.java +++ b/apps/user-service/src/main/java/com/gltkorea/icebang/domain/organization/controller/OrganizationController.java @@ -11,7 +11,7 @@ import com.gltkorea.icebang.common.dto.ApiResponse; import com.gltkorea.icebang.domain.organization.dto.OrganizationCardDto; -import com.gltkorea.icebang.domain.organization.dto.OrganizationOptionsDto; +import com.gltkorea.icebang.domain.organization.dto.OrganizationOptionDto; import com.gltkorea.icebang.domain.organization.service.OrganizationService; import lombok.RequiredArgsConstructor; @@ -28,7 +28,7 @@ public ResponseEntity>> getOrganizations() } @GetMapping("/{id}/options") - public ResponseEntity> getOrganizationDetails( + public ResponseEntity> getOrganizationDetails( @PathVariable BigInteger id) { return ResponseEntity.ok(ApiResponse.success(organizationService.getOrganizationOptions(id))); } diff --git a/apps/user-service/src/main/java/com/gltkorea/icebang/domain/organization/dto/OrganizationOptionsDto.java b/apps/user-service/src/main/java/com/gltkorea/icebang/domain/organization/dto/OrganizationOptionDto.java similarity index 55% rename from apps/user-service/src/main/java/com/gltkorea/icebang/domain/organization/dto/OrganizationOptionsDto.java rename to apps/user-service/src/main/java/com/gltkorea/icebang/domain/organization/dto/OrganizationOptionDto.java index c416d811..d31534eb 100644 --- a/apps/user-service/src/main/java/com/gltkorea/icebang/domain/organization/dto/OrganizationOptionsDto.java +++ b/apps/user-service/src/main/java/com/gltkorea/icebang/domain/organization/dto/OrganizationOptionDto.java @@ -2,9 +2,9 @@ import java.util.List; -import com.gltkorea.icebang.domain.department.dto.DepartmentsCardDto; +import com.gltkorea.icebang.domain.department.dto.DepartmentCardDo; import com.gltkorea.icebang.domain.position.dto.PositionCardDto; -import com.gltkorea.icebang.domain.roles.dto.RolesCardDto; +import com.gltkorea.icebang.domain.roles.dto.RoleCardDto; import lombok.AllArgsConstructor; import lombok.Builder; @@ -13,8 +13,8 @@ @Builder @Data @AllArgsConstructor -public class OrganizationOptionsDto { - List departments; +public class OrganizationOptionDto { + List departments; List positions; - List roles; + List roles; } diff --git a/apps/user-service/src/main/java/com/gltkorea/icebang/domain/organization/service/OrganizationService.java b/apps/user-service/src/main/java/com/gltkorea/icebang/domain/organization/service/OrganizationService.java index 4cebdfe5..84bcc54c 100644 --- a/apps/user-service/src/main/java/com/gltkorea/icebang/domain/organization/service/OrganizationService.java +++ b/apps/user-service/src/main/java/com/gltkorea/icebang/domain/organization/service/OrganizationService.java @@ -6,11 +6,11 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.gltkorea.icebang.domain.department.dto.DepartmentsCardDto; +import com.gltkorea.icebang.domain.department.dto.DepartmentCardDo; import com.gltkorea.icebang.domain.organization.dto.OrganizationCardDto; -import com.gltkorea.icebang.domain.organization.dto.OrganizationOptionsDto; +import com.gltkorea.icebang.domain.organization.dto.OrganizationOptionDto; import com.gltkorea.icebang.domain.position.dto.PositionCardDto; -import com.gltkorea.icebang.domain.roles.dto.RolesCardDto; +import com.gltkorea.icebang.domain.roles.dto.RoleCardDto; import com.gltkorea.icebang.mapper.OrganizationMapper; import lombok.RequiredArgsConstructor; @@ -25,12 +25,12 @@ public List getAllOrganizationList() { return organizationMapper.findAllOrganizations(); } - public OrganizationOptionsDto getOrganizationOptions(BigInteger id) { - List departments = organizationMapper.findDepartmentsByOrganizationId(id); + public OrganizationOptionDto getOrganizationOptions(BigInteger id) { + List departments = organizationMapper.findDepartmentsByOrganizationId(id); List positions = organizationMapper.findPositionsByOrganizationId(id); - List roles = organizationMapper.findRolesByOrganizationId(id); + List roles = organizationMapper.findRolesByOrganizationId(id); - return OrganizationOptionsDto.builder() + return OrganizationOptionDto.builder() .departments(departments) .positions(positions) .roles(roles) diff --git a/apps/user-service/src/main/java/com/gltkorea/icebang/domain/roles/dto/RolesCardDto.java b/apps/user-service/src/main/java/com/gltkorea/icebang/domain/roles/dto/RoleCardDto.java similarity index 92% rename from apps/user-service/src/main/java/com/gltkorea/icebang/domain/roles/dto/RolesCardDto.java rename to apps/user-service/src/main/java/com/gltkorea/icebang/domain/roles/dto/RoleCardDto.java index 709a08ff..5d468be5 100644 --- a/apps/user-service/src/main/java/com/gltkorea/icebang/domain/roles/dto/RolesCardDto.java +++ b/apps/user-service/src/main/java/com/gltkorea/icebang/domain/roles/dto/RoleCardDto.java @@ -11,7 +11,7 @@ @Builder @AllArgsConstructor @NoArgsConstructor -public class RolesCardDto { +public class RoleCardDto { private BigInteger id; private String name; private String description; diff --git a/apps/user-service/src/main/java/com/gltkorea/icebang/mapper/OrganizationMapper.java b/apps/user-service/src/main/java/com/gltkorea/icebang/mapper/OrganizationMapper.java index 2643af9f..a7624bc6 100644 --- a/apps/user-service/src/main/java/com/gltkorea/icebang/mapper/OrganizationMapper.java +++ b/apps/user-service/src/main/java/com/gltkorea/icebang/mapper/OrganizationMapper.java @@ -6,20 +6,20 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; -import com.gltkorea.icebang.domain.department.dto.DepartmentsCardDto; +import com.gltkorea.icebang.domain.department.dto.DepartmentCardDo; import com.gltkorea.icebang.domain.organization.dto.OrganizationCardDto; import com.gltkorea.icebang.domain.position.dto.PositionCardDto; -import com.gltkorea.icebang.domain.roles.dto.RolesCardDto; +import com.gltkorea.icebang.domain.roles.dto.RoleCardDto; @Mapper public interface OrganizationMapper { List findAllOrganizations(); - List findDepartmentsByOrganizationId( + List findDepartmentsByOrganizationId( @Param("organizationId") BigInteger organizationId); List findPositionsByOrganizationId( @Param("organizationId") BigInteger organizationId); - List findRolesByOrganizationId(@Param("organizationId") BigInteger organizationId); + List findRolesByOrganizationId(@Param("organizationId") BigInteger organizationId); } diff --git a/apps/user-service/src/main/resources/mybatis/mapper/OrganizationMapper.xml b/apps/user-service/src/main/resources/mybatis/mapper/OrganizationMapper.xml index cdc403fb..6a8201b8 100644 --- a/apps/user-service/src/main/resources/mybatis/mapper/OrganizationMapper.xml +++ b/apps/user-service/src/main/resources/mybatis/mapper/OrganizationMapper.xml @@ -14,7 +14,7 @@ From a4e39e61126d3a0c2252bcb1c9cbff63c0c067b7 Mon Sep 17 00:00:00 2001 From: jihukimme Date: Tue, 9 Sep 2025 16:48:59 +0900 Subject: [PATCH 07/10] =?UTF-8?q?chore:=20if=20not=20exits=20create=20sql?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/sql/schema.sql | 83 ++++++++++--------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/apps/user-service/src/main/resources/sql/schema.sql b/apps/user-service/src/main/resources/sql/schema.sql index 234bee14..894524bd 100644 --- a/apps/user-service/src/main/resources/sql/schema.sql +++ b/apps/user-service/src/main/resources/sql/schema.sql @@ -1,6 +1,7 @@ -- MariaDB 최적화된 스키마 (단수형 테이블 네이밍, 외래 키 제약조건 제거 버전) -CREATE TABLE IF NOT EXISTS `permission` ( +-- 윗줄에 drop 테이블 쿼리 or schema 분리 +CREATE TABLE `permission` ( `id` int unsigned NOT NULL AUTO_INCREMENT, `resource` varchar(100) NULL, `description` varchar(255) NULL, @@ -12,7 +13,7 @@ CREATE TABLE IF NOT EXISTS `permission` ( PRIMARY KEY (`id`) ); -CREATE TABLE IF NOT EXISTS `organization` ( +CREATE TABLE `organization` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `name` varchar(150) NULL, `domain_name` varchar(100) NULL, @@ -21,7 +22,7 @@ CREATE TABLE IF NOT EXISTS `organization` ( PRIMARY KEY (`id`) ); -CREATE TABLE IF NOT EXISTS `role` ( +CREATE TABLE `role` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `organization_id` bigint unsigned NULL, `name` varchar(100) NULL, @@ -29,7 +30,7 @@ CREATE TABLE IF NOT EXISTS `role` ( PRIMARY KEY (`id`) ); -CREATE TABLE IF NOT EXISTS `user` ( +CREATE TABLE `user` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `name` varchar(50) NULL, `email` varchar(100) NULL, @@ -40,21 +41,21 @@ CREATE TABLE IF NOT EXISTS `user` ( PRIMARY KEY (`id`) ); -CREATE TABLE IF NOT EXISTS `department` ( +CREATE TABLE `department` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `organization_id` bigint unsigned NOT NULL, `name` varchar(100) NULL, PRIMARY KEY (`id`) ); -CREATE TABLE IF NOT EXISTS `position` ( +CREATE TABLE `position` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `organization_id` bigint unsigned NOT NULL, `title` varchar(100) NULL, PRIMARY KEY (`id`) ); -CREATE TABLE IF NOT EXISTS `user_organization` ( +CREATE TABLE `user_organization` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `user_id` bigint unsigned NOT NULL, `organization_id` bigint unsigned NOT NULL, @@ -67,7 +68,7 @@ CREATE TABLE IF NOT EXISTS `user_organization` ( PRIMARY KEY (`id`) ); -CREATE TABLE IF NOT EXISTS `role_permission` ( +CREATE TABLE `role_permission` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `role_id` bigint unsigned NOT NULL, `permission_id` int unsigned NOT NULL, @@ -75,7 +76,7 @@ CREATE TABLE IF NOT EXISTS `role_permission` ( UNIQUE KEY `uk_role_permission` (`role_id`, `permission_id`) ); -CREATE TABLE IF NOT EXISTS `user_role` ( +CREATE TABLE `user_role` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `role_id` bigint unsigned NOT NULL, `user_organization_id` bigint unsigned NOT NULL, @@ -84,18 +85,18 @@ CREATE TABLE IF NOT EXISTS `user_role` ( ); -- 성능 최적화를 위한 인덱스 -CREATE INDEX IF NOT EXISTS `idx_user_email` ON `user` (`email`); -CREATE INDEX IF NOT EXISTS `idx_user_status` ON `user` (`status`); -CREATE INDEX IF NOT EXISTS `idx_user_organization_user` ON `user_organization` (`user_id`); -CREATE INDEX IF NOT EXISTS `idx_user_organization_org` ON `user_organization` (`organization_id`); -CREATE INDEX IF NOT EXISTS `idx_user_organization_status` ON `user_organization` (`status`); -CREATE INDEX IF NOT EXISTS `idx_role_org` ON `role` (`organization_id`); -CREATE INDEX IF NOT EXISTS `idx_permission_resource` ON `permission` (`resource`); -CREATE INDEX IF NOT EXISTS `idx_permission_active` ON `permission` (`is_active`); +CREATE INDEX `idx_user_email` ON `user` (`email`); +CREATE INDEX `idx_user_status` ON `user` (`status`); +CREATE INDEX `idx_user_organization_user` ON `user_organization` (`user_id`); +CREATE INDEX `idx_user_organization_org` ON `user_organization` (`organization_id`); +CREATE INDEX `idx_user_organization_status` ON `user_organization` (`status`); +CREATE INDEX `idx_role_org` ON `role` (`organization_id`); +CREATE INDEX `idx_permission_resource` ON `permission` (`resource`); +CREATE INDEX `idx_permission_active` ON `permission` (`is_active`); -CREATE TABLE IF NOT EXISTS `workflow` ( +CREATE TABLE `workflow` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL UNIQUE, `description` text NULL, @@ -107,7 +108,7 @@ CREATE TABLE IF NOT EXISTS `workflow` ( PRIMARY KEY (`id`) ); -CREATE TABLE IF NOT EXISTS `schedule` ( +CREATE TABLE `schedule` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `workflow_id` bigint unsigned NOT NULL, `cron_expression` varchar(50) NULL, @@ -122,7 +123,7 @@ CREATE TABLE IF NOT EXISTS `schedule` ( PRIMARY KEY (`id`) ); -CREATE TABLE IF NOT EXISTS `job` ( +CREATE TABLE `job` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL UNIQUE, `description` text NULL, @@ -134,7 +135,7 @@ CREATE TABLE IF NOT EXISTS `job` ( PRIMARY KEY (`id`) ); -CREATE TABLE IF NOT EXISTS `task` ( +CREATE TABLE `task` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL UNIQUE, `type` varchar(50) NULL, @@ -144,7 +145,7 @@ CREATE TABLE IF NOT EXISTS `task` ( PRIMARY KEY (`id`) ); -CREATE TABLE IF NOT EXISTS `workflow_job` ( +CREATE TABLE `workflow_job` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `workflow_id` bigint unsigned NOT NULL, `job_id` bigint unsigned NOT NULL, @@ -152,7 +153,7 @@ CREATE TABLE IF NOT EXISTS `workflow_job` ( UNIQUE KEY `uk_workflow_job` (`workflow_id`, `job_id`) ); -CREATE TABLE IF NOT EXISTS `job_task` ( +CREATE TABLE `job_task` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `job_id` bigint unsigned NOT NULL, `task_id` bigint unsigned NOT NULL, @@ -161,7 +162,7 @@ CREATE TABLE IF NOT EXISTS `job_task` ( UNIQUE KEY `uk_job_task` (`job_id`, `task_id`) ); -CREATE TABLE IF NOT EXISTS `execution_log` ( +CREATE TABLE `execution_log` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `execution_type` varchar(20) NULL COMMENT 'task, schedule, job, workflow', `source_id` bigint unsigned NULL COMMENT '모든 데이터에 대한 ID ex: job_id, schedule_id, task_id, ...', @@ -174,7 +175,7 @@ CREATE TABLE IF NOT EXISTS `execution_log` ( INDEX `idx_source_id_type` (`source_id`, `execution_type`) ); -CREATE TABLE IF NOT EXISTS `task_io_data` ( +CREATE TABLE `task_io_data` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `task_run_id` bigint unsigned NOT NULL, `io_type` varchar(10) NOT NULL COMMENT 'INPUT, OUTPUT', @@ -189,7 +190,7 @@ CREATE TABLE IF NOT EXISTS `task_io_data` ( INDEX `idx_task_io_name` (`name`) ); -CREATE TABLE IF NOT EXISTS `config` ( +CREATE TABLE `config` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `target_type` varchar(50) NULL COMMENT 'user, job, workflow', `target_id` bigint unsigned NULL, @@ -202,7 +203,7 @@ CREATE TABLE IF NOT EXISTS `config` ( UNIQUE KEY `uk_config_target` (`target_type`, `target_id`) ); -CREATE TABLE IF NOT EXISTS `category` ( +CREATE TABLE `category` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `name` varchar(100) NULL, `description` text NULL, @@ -211,7 +212,7 @@ CREATE TABLE IF NOT EXISTS `category` ( PRIMARY KEY (`id`) ); -CREATE TABLE IF NOT EXISTS `user_config` ( +CREATE TABLE `user_config` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `user_id` bigint unsigned NOT NULL, `type` varchar(50) NULL, @@ -224,20 +225,20 @@ CREATE TABLE IF NOT EXISTS `user_config` ( ); -- 인덱스 추가 (성능 최적화) -CREATE INDEX IF NOT EXISTS `idx_schedule_workflow` ON `schedule` (`workflow_id`); -CREATE INDEX IF NOT EXISTS `idx_job_enabled` ON `job` (`is_enabled`); -CREATE INDEX IF NOT EXISTS `idx_task_type` ON `task` (`type`); -CREATE INDEX IF NOT EXISTS `idx_workflow_enabled` ON `workflow` (`is_enabled`); -CREATE UNIQUE INDEX IF NOT EXISTS `uk_schedule_workflow` ON `schedule` (`workflow_id`); -CREATE UNIQUE INDEX IF NOT EXISTS `uk_job_name` ON `job` (`name`); -CREATE UNIQUE INDEX IF NOT EXISTS `uk_task_name` ON `task` (`name`); -CREATE UNIQUE INDEX IF NOT EXISTS `uk_workflow_name` ON `workflow` (`name`); -CREATE INDEX IF NOT EXISTS `idx_user_config_user` ON `user_config` (`user_id`); +CREATE INDEX `idx_schedule_workflow` ON `schedule` (`workflow_id`); +CREATE INDEX `idx_job_enabled` ON `job` (`is_enabled`); +CREATE INDEX `idx_task_type` ON `task` (`type`); +CREATE INDEX `idx_workflow_enabled` ON `workflow` (`is_enabled`); +CREATE UNIQUE INDEX `uk_schedule_workflow` ON `schedule` (`workflow_id`); +CREATE UNIQUE INDEX `uk_job_name` ON `job` (`name`); +CREATE UNIQUE INDEX `uk_task_name` ON `task` (`name`); +CREATE UNIQUE INDEX `uk_workflow_name` ON `workflow` (`name`); +CREATE INDEX `idx_user_config_user` ON `user_config` (`user_id`); -- 워크플로우 실행 테이블 -CREATE TABLE IF NOT EXISTS `workflow_run` ( +CREATE TABLE `workflow_run` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `workflow_id` bigint unsigned NOT NULL, `trace_id` char(36) NOT NULL, @@ -256,7 +257,7 @@ CREATE TABLE IF NOT EXISTS `workflow_run` ( ); -- Job 실행 테이블 -CREATE TABLE IF NOT EXISTS `job_run` ( +CREATE TABLE `job_run` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `workflow_run_id` bigint unsigned NOT NULL, `job_id` bigint unsigned NOT NULL, @@ -272,7 +273,7 @@ CREATE TABLE IF NOT EXISTS `job_run` ( ); -- Task 실행 테이블 -CREATE TABLE IF NOT EXISTS `task_run` ( +CREATE TABLE `task_run` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `job_run_id` bigint unsigned NOT NULL, `task_id` bigint unsigned NOT NULL, @@ -287,4 +288,4 @@ CREATE TABLE IF NOT EXISTS `task_run` ( INDEX `idx_task_run_task_id` (`task_id`) ); -CREATE INDEX IF NOT EXISTS `idx_task_io_data_task_run_id` ON `task_io_data` (`task_run_id`); \ No newline at end of file +CREATE INDEX `idx_task_io_data_task_run_id` ON `task_io_data` (`task_run_id`); \ No newline at end of file From ab16fcae48d17cce2a11554202e358febedefddc Mon Sep 17 00:00:00 2001 From: jihukimme Date: Tue, 9 Sep 2025 16:52:46 +0900 Subject: [PATCH 08/10] chore: Drop all table before create shcema --- .../src/main/resources/sql/schema.sql | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/apps/user-service/src/main/resources/sql/schema.sql b/apps/user-service/src/main/resources/sql/schema.sql index 894524bd..cab52f93 100644 --- a/apps/user-service/src/main/resources/sql/schema.sql +++ b/apps/user-service/src/main/resources/sql/schema.sql @@ -1,6 +1,23 @@ --- MariaDB 최적화된 스키마 (단수형 테이블 네이밍, 외래 키 제약조건 제거 버전) --- 윗줄에 drop 테이블 쿼리 or schema 분리 +SET FOREIGN_KEY_CHECKS = 0; +SET @tables = NULL; + +-- 1. 데이터베이스 내 모든 테이블 목록을 가져와 변수에 저장 +SELECT GROUP_CONCAT('`', table_name, '`') INTO @tables +FROM information_schema.tables +WHERE table_schema = (SELECT DATABASE()); + +-- 2. 변수 값이 NULL인 경우를 대비하여 조건문 추가 및 DROP TABLE 구문 생성 +SET @drop_tables_sql = IFNULL(CONCAT('DROP TABLE ', @tables), 'SELECT "No tables to drop";'); + +-- 3. 동적 SQL 실행 +PREPARE stmt FROM @drop_tables_sql; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; + +SET FOREIGN_KEY_CHECKS = 1; + +-- MariaDB 최적화된 스키마 (단수형 테이블 네이밍, 외래 키 제약조건 제거 버전) CREATE TABLE `permission` ( `id` int unsigned NOT NULL AUTO_INCREMENT, `resource` varchar(100) NULL, From a8d10f27284bdc3d6fd4f435c006ffe53f1115a0 Mon Sep 17 00:00:00 2001 From: jihukimme Date: Tue, 9 Sep 2025 17:36:32 +0900 Subject: [PATCH 09/10] =?UTF-8?q?fix:=20Schema=20SQL=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A6=BD=ED=8A=B8=EB=A5=BC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/user-service/src/main/resources/sql/schema.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/user-service/src/main/resources/sql/schema.sql b/apps/user-service/src/main/resources/sql/schema.sql index cab52f93..b6e5184c 100644 --- a/apps/user-service/src/main/resources/sql/schema.sql +++ b/apps/user-service/src/main/resources/sql/schema.sql @@ -3,7 +3,7 @@ SET FOREIGN_KEY_CHECKS = 0; SET @tables = NULL; -- 1. 데이터베이스 내 모든 테이블 목록을 가져와 변수에 저장 -SELECT GROUP_CONCAT('`', table_name, '`') INTO @tables +SELECT GROUP_CONCAT(table_name SEPARATOR ',') INTO @tables FROM information_schema.tables WHERE table_schema = (SELECT DATABASE()); From da05e36c436c0cd17edba7d92cf1a474d6f5ed75 Mon Sep 17 00:00:00 2001 From: jihukimme Date: Tue, 9 Sep 2025 18:01:03 +0900 Subject: [PATCH 10/10] =?UTF-8?q?fix:=20Drop=20SQL=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A6=BD=ED=8A=B8=20=EB=B6=84=EB=A6=AC=20=EB=B0=8F=20Schema=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/application-develop.yml | 4 +++- .../main/resources/application-test-e2e.yml | 4 +++- .../main/resources/application-test-unit.yml | 4 +++- .../src/main/resources/sql/00-drop-h2.sql | 6 ++++++ .../src/main/resources/sql/00-drop-maria.sql | 18 ++++++++++++++++++ .../sql/{schema.sql => 01-schema.sql} | 19 ------------------- .../icebang/DatabaseConnectionTest.java | 2 +- 7 files changed, 34 insertions(+), 23 deletions(-) create mode 100644 apps/user-service/src/main/resources/sql/00-drop-h2.sql create mode 100644 apps/user-service/src/main/resources/sql/00-drop-maria.sql rename apps/user-service/src/main/resources/sql/{schema.sql => 01-schema.sql} (95%) diff --git a/apps/user-service/src/main/resources/application-develop.yml b/apps/user-service/src/main/resources/application-develop.yml index 773a7333..6d9a8ea3 100644 --- a/apps/user-service/src/main/resources/application-develop.yml +++ b/apps/user-service/src/main/resources/application-develop.yml @@ -26,7 +26,9 @@ spring: sql: init: mode: always - schema-locations: classpath:sql/schema.sql + schema-locations: + - classpath:sql/00-drop-maria.sql + - classpath:sql/01-schema.sql data-locations: - classpath:sql/00-truncate.sql - classpath:sql/01-insert-internal-users.sql diff --git a/apps/user-service/src/main/resources/application-test-e2e.yml b/apps/user-service/src/main/resources/application-test-e2e.yml index 7703f4a3..8759b298 100644 --- a/apps/user-service/src/main/resources/application-test-e2e.yml +++ b/apps/user-service/src/main/resources/application-test-e2e.yml @@ -6,7 +6,9 @@ spring: sql: init: mode: always - schema-locations: classpath:sql/schema.sql + schema-locations: + - classpath:sql/00-drop-maria.sql + - classpath:sql/01-schema.sql encoding: UTF-8 mybatis: diff --git a/apps/user-service/src/main/resources/application-test-unit.yml b/apps/user-service/src/main/resources/application-test-unit.yml index fec65f43..4b36c77f 100644 --- a/apps/user-service/src/main/resources/application-test-unit.yml +++ b/apps/user-service/src/main/resources/application-test-unit.yml @@ -37,7 +37,9 @@ spring: sql: init: mode: always - schema-locations: classpath:sql/schema.sql + schema-locations: + - classpath:sql/00-drop-h2.sql + - classpath:sql/01-schema.sql encoding: UTF-8 mybatis: diff --git a/apps/user-service/src/main/resources/sql/00-drop-h2.sql b/apps/user-service/src/main/resources/sql/00-drop-h2.sql new file mode 100644 index 00000000..d0c7bda3 --- /dev/null +++ b/apps/user-service/src/main/resources/sql/00-drop-h2.sql @@ -0,0 +1,6 @@ +SET FOREIGN_KEY_CHECKS = 0; + +-- H2에서 모든 테이블과 객체를 삭제하는 올바른 구문 +DROP ALL OBJECTS; + +SET FOREIGN_KEY_CHECKS = 1; \ No newline at end of file diff --git a/apps/user-service/src/main/resources/sql/00-drop-maria.sql b/apps/user-service/src/main/resources/sql/00-drop-maria.sql new file mode 100644 index 00000000..d93b57b4 --- /dev/null +++ b/apps/user-service/src/main/resources/sql/00-drop-maria.sql @@ -0,0 +1,18 @@ +SET FOREIGN_KEY_CHECKS = 0; +SET @tables = NULL; + +-- 1. 데이터베이스 내 모든 테이블 목록을 가져와 변수에 저장 +-- 백틱(`)을 사용하여 테이블 이름에 공백이나 특수 문자가 있어도 안전하게 처리합니다. +SELECT GROUP_CONCAT(CONCAT('`', table_name, '`')) INTO @tables +FROM information_schema.tables +WHERE table_schema = DATABASE(); + +-- 2. 변수 값이 NULL인 경우를 대비하여 조건문 추가 및 DROP TABLE 구문 생성 +SET @drop_tables_sql = IFNULL(CONCAT('DROP TABLE ', @tables), 'SELECT "No tables to drop";'); + +-- 3. 동적 SQL 실행 +PREPARE stmt FROM @drop_tables_sql; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; + +SET FOREIGN_KEY_CHECKS = 1; \ No newline at end of file diff --git a/apps/user-service/src/main/resources/sql/schema.sql b/apps/user-service/src/main/resources/sql/01-schema.sql similarity index 95% rename from apps/user-service/src/main/resources/sql/schema.sql rename to apps/user-service/src/main/resources/sql/01-schema.sql index b6e5184c..138425fc 100644 --- a/apps/user-service/src/main/resources/sql/schema.sql +++ b/apps/user-service/src/main/resources/sql/01-schema.sql @@ -1,22 +1,3 @@ - -SET FOREIGN_KEY_CHECKS = 0; -SET @tables = NULL; - --- 1. 데이터베이스 내 모든 테이블 목록을 가져와 변수에 저장 -SELECT GROUP_CONCAT(table_name SEPARATOR ',') INTO @tables -FROM information_schema.tables -WHERE table_schema = (SELECT DATABASE()); - --- 2. 변수 값이 NULL인 경우를 대비하여 조건문 추가 및 DROP TABLE 구문 생성 -SET @drop_tables_sql = IFNULL(CONCAT('DROP TABLE ', @tables), 'SELECT "No tables to drop";'); - --- 3. 동적 SQL 실행 -PREPARE stmt FROM @drop_tables_sql; -EXECUTE stmt; -DEALLOCATE PREPARE stmt; - -SET FOREIGN_KEY_CHECKS = 1; - -- MariaDB 최적화된 스키마 (단수형 테이블 네이밍, 외래 키 제약조건 제거 버전) CREATE TABLE `permission` ( `id` int unsigned NOT NULL AUTO_INCREMENT, diff --git a/apps/user-service/src/test/java/com/gltkorea/icebang/DatabaseConnectionTest.java b/apps/user-service/src/test/java/com/gltkorea/icebang/DatabaseConnectionTest.java index e744873b..c15170cc 100644 --- a/apps/user-service/src/test/java/com/gltkorea/icebang/DatabaseConnectionTest.java +++ b/apps/user-service/src/test/java/com/gltkorea/icebang/DatabaseConnectionTest.java @@ -28,7 +28,7 @@ // @ActiveProfiles("test") // application-test-unit.yml 설정을 활성화 // @Transactional // 테스트 후 데이터 롤백 // @Sql( -// scripts = {"classpath:sql/create-schema.sql", "classpath:sql/insert-user-data.sql"}, +// scripts = {"classpath:sql/create-01-schema.sql", "classpath:sql/insert-user-data.sql"}, // executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) // class DatabaseConnectionTest { //