From e8d0a1d4b4f7b86365adc45a5d179a7152786100 Mon Sep 17 00:00:00 2001 From: wonho Date: Wed, 29 Oct 2025 17:58:36 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B0=B1=EC=97=94=EB=93=9C=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=EC=84=A4=EC=A0=95=20=EB=B0=8F=20CORS=20?= =?UTF-8?q?=EC=A0=95=EC=B1=85=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CORS 설정에 https 프로토콜 지원 추가 - User-Service CORS를 모든 Origin 허용으로 변경 - ConfigMap CORS_ALLOWED_ORIGINS 확장 - User-Service DB migration 스크립트 추가 - Application 설정 파일 업데이트 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- deployment/k8s/common/cm-common.yaml | 2 +- .../src/main/resources/application.yml | 12 ++++- user-service/build.gradle | 4 ++ .../kt/event/user/config/SecurityConfig.java | 13 +++--- .../src/main/resources/application.yml | 10 ++++- .../V001__migrate_user_id_to_uuid.sql | 45 +++++++++++++++++++ .../V002__change_user_id_to_uuid.sql | 45 +++++++++++++++++++ 7 files changed, 120 insertions(+), 11 deletions(-) create mode 100644 user-service/src/main/resources/db/migration/V001__migrate_user_id_to_uuid.sql create mode 100644 user-service/src/main/resources/db/migration/V002__change_user_id_to_uuid.sql diff --git a/deployment/k8s/common/cm-common.yaml b/deployment/k8s/common/cm-common.yaml index d9b98bf..8d6597d 100644 --- a/deployment/k8s/common/cm-common.yaml +++ b/deployment/k8s/common/cm-common.yaml @@ -20,7 +20,7 @@ data: EXCLUDE_REDIS: "" # CORS Configuration - CORS_ALLOWED_ORIGINS: "http://localhost:8081,http://localhost:8082,http://localhost:8083,http://localhost:8084,http://kt-event-marketing.20.214.196.128.nip.io" + CORS_ALLOWED_ORIGINS: "http://localhost:8081,http://localhost:8082,http://localhost:8083,http://localhost:8084,http://kt-event-marketing.20.214.196.128.nip.io,http://kt-event-marketing-api.20.214.196.128.nip.io,http://*.20.214.196.128.nip.io,https://kt-event-marketing.20.214.196.128.nip.io,https://kt-event-marketing-api.20.214.196.128.nip.io,https://*.20.214.196.128.nip.io" CORS_ALLOWED_METHODS: "GET,POST,PUT,DELETE,OPTIONS,PATCH" CORS_ALLOWED_HEADERS: "*" CORS_ALLOW_CREDENTIALS: "true" diff --git a/participation-service/src/main/resources/application.yml b/participation-service/src/main/resources/application.yml index 566a865..2f35890 100644 --- a/participation-service/src/main/resources/application.yml +++ b/participation-service/src/main/resources/application.yml @@ -98,4 +98,14 @@ management: livenessState: enabled: true readinessState: - enabled: true \ No newline at end of file + enabled: true + +# OpenAPI Documentation +springdoc: + api-docs: + path: /v3/api-docs + swagger-ui: + path: /swagger-ui.html + tags-sorter: alpha + operations-sorter: alpha + show-actuator: false \ No newline at end of file diff --git a/user-service/build.gradle b/user-service/build.gradle index 421e125..076744a 100644 --- a/user-service/build.gradle +++ b/user-service/build.gradle @@ -12,6 +12,10 @@ dependencies { // OpenFeign for external API calls (사업자번호 검증) implementation 'org.springframework.cloud:spring-cloud-starter-openfeign' + // Flyway for database migration + implementation 'org.flywaydb:flyway-core' + implementation 'org.flywaydb:flyway-database-postgresql' + // H2 Database for development runtimeOnly 'com.h2database:h2' diff --git a/user-service/src/main/java/com/kt/event/user/config/SecurityConfig.java b/user-service/src/main/java/com/kt/event/user/config/SecurityConfig.java index 9e891c3..064c938 100644 --- a/user-service/src/main/java/com/kt/event/user/config/SecurityConfig.java +++ b/user-service/src/main/java/com/kt/event/user/config/SecurityConfig.java @@ -65,18 +65,14 @@ public class SecurityConfig { public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); - // 환경변수에서 허용할 Origin 패턴 설정 - String[] origins = allowedOrigins.split(","); - configuration.setAllowedOriginPatterns(Arrays.asList(origins)); + // 모든 Origin 허용 + configuration.setAllowedOriginPatterns(Arrays.asList("*")); // 허용할 HTTP 메소드 configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS")); // 허용할 헤더 - configuration.setAllowedHeaders(Arrays.asList( - "Authorization", "Content-Type", "X-Requested-With", "Accept", - "Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers" - )); + configuration.setAllowedHeaders(Arrays.asList("*")); // 자격 증명 허용 configuration.setAllowCredentials(true); @@ -84,6 +80,9 @@ public class SecurityConfig { // Pre-flight 요청 캐시 시간 configuration.setMaxAge(3600L); + // Exposed Headers 추가 + configuration.setExposedHeaders(Arrays.asList("Authorization", "Content-Type")); + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", configuration); return source; diff --git a/user-service/src/main/resources/application.yml b/user-service/src/main/resources/application.yml index 427f96e..0b96783 100644 --- a/user-service/src/main/resources/application.yml +++ b/user-service/src/main/resources/application.yml @@ -31,7 +31,13 @@ spring: use_sql_comments: true dialect: ${JPA_DIALECT:org.hibernate.dialect.PostgreSQLDialect} hibernate: - ddl-auto: ${DDL_AUTO:update} + ddl-auto: ${DDL_AUTO:validate} + + # Flyway Configuration + flyway: + enabled: ${FLYWAY_ENABLED:true} + baseline-on-migrate: ${FLYWAY_BASELINE:true} + locations: classpath:db/migration # Auto-configuration exclusions for development without external services autoconfigure: @@ -76,7 +82,7 @@ jwt: # CORS Configuration cors: - allowed-origins: ${CORS_ALLOWED_ORIGINS:http://localhost:8081,http://localhost:8082,http://localhost:8083,http://localhost:8084,http://kt-event-marketing.20.214.196.128.nip.io} + allowed-origins: ${CORS_ALLOWED_ORIGINS:http://localhost:8081,http://localhost:8082,http://localhost:8083,http://localhost:8084,http://kt-event-marketing.20.214.196.128.nip.io,http://kt-event-marketing-api.20.214.196.128.nip.io,http://*.kt-event-marketing-api.20.214.196.128.nip.io,http://*.20.214.196.128.nip.io} allowed-methods: ${CORS_ALLOWED_METHODS:GET,POST,PUT,DELETE,OPTIONS,PATCH} allowed-headers: ${CORS_ALLOWED_HEADERS:*} allow-credentials: ${CORS_ALLOW_CREDENTIALS:true} diff --git a/user-service/src/main/resources/db/migration/V001__migrate_user_id_to_uuid.sql b/user-service/src/main/resources/db/migration/V001__migrate_user_id_to_uuid.sql new file mode 100644 index 0000000..e0e62bc --- /dev/null +++ b/user-service/src/main/resources/db/migration/V001__migrate_user_id_to_uuid.sql @@ -0,0 +1,45 @@ +-- Migration script to change user_id from BIGINT to UUID +-- WARNING: This will delete all existing data in users and stores tables +-- Make sure to backup your data before running this script! + +-- Step 1: Drop dependent tables/constraints +DROP TABLE IF EXISTS stores CASCADE; +DROP TABLE IF EXISTS users CASCADE; + +-- Step 2: Create users table with UUID +CREATE TABLE users ( + user_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + name VARCHAR(50) NOT NULL, + phone_number VARCHAR(20) NOT NULL UNIQUE, + email VARCHAR(100) NOT NULL UNIQUE, + password_hash VARCHAR(255) NOT NULL, + role VARCHAR(20) NOT NULL DEFAULT 'OWNER', + status VARCHAR(20) NOT NULL DEFAULT 'ACTIVE', + last_login_at TIMESTAMP, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +-- Step 3: Create indexes on users table +CREATE UNIQUE INDEX idx_user_phone ON users(phone_number); +CREATE UNIQUE INDEX idx_user_email ON users(email); + +-- Step 4: Create stores table with UUID foreign key +CREATE TABLE stores ( + store_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + name VARCHAR(100) NOT NULL, + industry VARCHAR(50), + address VARCHAR(255) NOT NULL, + business_hours VARCHAR(255), + user_id UUID NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_stores_user FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE +); + +-- Step 5: Create index on stores table +CREATE INDEX idx_stores_user ON stores(user_id); + +-- Enable UUID extension if not already enabled +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; +CREATE EXTENSION IF NOT EXISTS "pgcrypto"; diff --git a/user-service/src/main/resources/db/migration/V002__change_user_id_to_uuid.sql b/user-service/src/main/resources/db/migration/V002__change_user_id_to_uuid.sql new file mode 100644 index 0000000..fc52011 --- /dev/null +++ b/user-service/src/main/resources/db/migration/V002__change_user_id_to_uuid.sql @@ -0,0 +1,45 @@ +-- Migration script V002: Change user_id and store_id from BIGINT to UUID +-- WARNING: This will delete all existing data in users and stores tables +-- Make sure to backup your data before running this script! + +-- Step 1: Drop dependent tables/constraints +DROP TABLE IF EXISTS stores CASCADE; +DROP TABLE IF EXISTS users CASCADE; + +-- Step 2: Create users table with UUID +CREATE TABLE users ( + user_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + name VARCHAR(50) NOT NULL, + phone_number VARCHAR(20) NOT NULL UNIQUE, + email VARCHAR(100) NOT NULL UNIQUE, + password_hash VARCHAR(255) NOT NULL, + role VARCHAR(20) NOT NULL DEFAULT 'OWNER', + status VARCHAR(20) NOT NULL DEFAULT 'ACTIVE', + last_login_at TIMESTAMP, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +-- Step 3: Create indexes on users table +CREATE UNIQUE INDEX idx_user_phone ON users(phone_number); +CREATE UNIQUE INDEX idx_user_email ON users(email); + +-- Step 4: Create stores table with UUID foreign key +CREATE TABLE stores ( + store_id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + name VARCHAR(100) NOT NULL, + industry VARCHAR(50), + address VARCHAR(255) NOT NULL, + business_hours VARCHAR(255), + user_id UUID NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + CONSTRAINT fk_stores_user FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE +); + +-- Step 5: Create index on stores table +CREATE INDEX idx_stores_user ON stores(user_id); + +-- Enable UUID extension if not already enabled +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; +CREATE EXTENSION IF NOT EXISTS "pgcrypto";