Skip to content

Conversation

@Gwonwoo-Nam
Copy link
Contributor

@Gwonwoo-Nam Gwonwoo-Nam commented May 18, 2025

🟢 구현내용

🧩 고민과 해결과정

Summary by CodeRabbit

  • Chores
    • Added a complete database initialization script to set up all required tables and configurations for the application’s database environment.
    • Updated development environment CORS settings for improved cross-origin request handling.
    • Modified development datasource configuration to use a fixed local database URL and credentials for easier setup.

@coderabbitai
Copy link

coderabbitai bot commented May 18, 2025

"""

Walkthrough

A comprehensive MySQL initialization script was added, defining the schema for the upbrella_prod database. The script sets session variables, drops existing tables, and creates new tables with specified columns, data types, keys, and character sets. It concludes by restoring session variables, focusing solely on schema creation without inserting data. Additionally, the CORS configuration for the "dev" profile was refactored from a custom servlet filter to a Spring WebMvcConfigurer implementation with updated allowed origins, methods, headers, credentials, and max age. The application-dev.yml datasource configuration was changed from environment-variable-based to a mostly hardcoded local MySQL connection with a fixed username and environment-variable password.

Changes

File(s) Change Summary
src/main/resources/db/init.sql Added a full MySQL initialization script: sets session/global variables, drops and recreates 12 tables with defined schemas, restores session settings. No data insertion.
src/main/kotlin/upbrella/be/config/DevCorsConfig.kt Refactored CORS config from a Filter to a WebMvcConfigurer implementation; updated allowed origins, methods, headers, credentials, and max age; changed annotation from @Component to @Configuration.
src/main/resources/application-dev.yml Modified datasource config to use a hardcoded local MySQL JDBC URL and fixed username root, retaining environment variable for password; driver class unchanged.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Frontend Client
    participant SpringApp as Spring Application

    Client->>SpringApp: Send HTTP request with Origin header
    SpringApp->>SpringApp: Check CORS config (allowed origins, methods, headers)
    SpringApp-->>Client: Respond with appropriate CORS headers (Access-Control-Allow-Origin, etc.)
Loading

Poem

🐇 A hop, a skip, the tables rise,
With schemas set beneath the skies.
Cors now dances, smooth and bright,
Allowing origins in clear sight.
A local root, a secret key,
The dev world hums in harmony!
🌱✨
"""

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 781ba70 and ed26d02.

📒 Files selected for processing (1)
  • src/main/kotlin/upbrella/be/config/DevCorsConfig.kt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/kotlin/upbrella/be/config/DevCorsConfig.kt
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 11

🧹 Nitpick comments (8)
src/main/resources/db/init.sql (8)

7-16: Remove or simplify session variable statements requiring elevated privileges.
The dumped session and global variable manipulations (e.g., SET @OLD_* and disabling SQL notes/log bin) may require SUPER privileges on production/RDS and can cause errors. Consider trimming to only the necessary SET NAMES utf8mb4 and disabling foreign key/unique checks.


30-38: Reset AUTO_INCREMENT to 1 for a clean schema.
The AUTO_INCREMENT=3 on the new black_list table reflects existing data state. For an initial schema setup, reset to default (start at 1) unless preserving sequence continuity is required.


67-67: Avoid reserved keywords for column names.
Using type (a MySQL keyword) as a column name can lead to confusion. Consider renaming to classification_type or similar.


69-70: Consider spatial data types for geolocation.
Storing latitude/longitude as DOUBLE works, but using MySQL spatial types (POINT) and spatial indexes can optimize geospatial queries if your application will perform radius or proximity searches.


84-88: Reevaluate column length for content.
Using VARCHAR(401) is unconventional (odd limit) and may still truncate content if requirements change. Consider:

  • Switching to TEXT for variable-length content.
  • Standardizing to a round number, e.g., VARCHAR(500).

Also applies to: 126-130


142-142: Avoid using reserved keywords as column names.
The column count conflicts with the SQL aggregate function. Renaming it to quantity or total_count improves clarity and avoids potential parsing issues.


219-219: Review data type choice for uuid.
Storing UUIDs in a numeric BIGINT may not align with standard UUID formats. If using standard GUIDs, consider CHAR(36) or BINARY(16) for uuid.


232-233: Avoid reserved table names.
Naming the table user (a reserved keyword) can lead to confusion and quoting overhead. Consider renaming to users or app_user.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between a82705a and 02bfef5.

📒 Files selected for processing (1)
  • src/main/resources/db/init.sql (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (1)
src/main/resources/db/init.sql (1)

251-259: Session variable restoration is properly handled.
The script correctly restores SQL_LOG_BIN, time zone, SQL modes, and foreign key/unique checks at the end. This ensures the session state is returned to its original configuration.

Comment on lines +165 to +167
`store_meta_id` int DEFAULT NULL,
`umbrella_location` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add foreign key and index on store_meta_id.
store_detail.store_meta_id lacks an explicit index and constraint. Include:

INDEX idx_store_detail_store_meta (store_meta_id),
FOREIGN KEY (store_meta_id) REFERENCES store_meta(id)

for integrity and performance.

🤖 Prompt for AI Agents
In src/main/resources/db/init.sql around lines 165 to 167, the column
store_meta_id in the store_detail table lacks an index and foreign key
constraint. Add an index named idx_store_detail_store_meta on store_meta_id and
define a foreign key constraint referencing store_meta(id) to ensure referential
integrity and improve query performance.

-- GTID state at the beginning of the backup
--

SET @@GLOBAL.GTID_PURGED=/*!80000 '+'*/ '';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Eliminate GTID_PURGED assignment for compatibility with managed environments.
SET @@GLOBAL.GTID_PURGED often fails on RDS or restricted MySQL instances. Remove or externalize GTID handling to avoid permission errors.

🤖 Prompt for AI Agents
In src/main/resources/db/init.sql at line 24, remove the line setting
@@GLOBAL.GTID_PURGED to avoid permission errors in managed MySQL environments
like RDS. This eliminates the assignment that is often disallowed, improving
compatibility. If GTID handling is necessary, externalize it to a script or
process with appropriate privileges outside this initialization script.

/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `black_list` (
`id` int NOT NULL AUTO_INCREMENT,
`social_id` bigint DEFAULT NULL,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Unify social_id column types across tables.
black_list.social_id is BIGINT, but user.social_id is VARCHAR(500). Choose a single type (e.g., VARCHAR(255) or BIGINT) to enforce consistency and avoid implicit conversions.

Also applies to: 240-240

🤖 Prompt for AI Agents
In src/main/resources/db/init.sql at lines 35 and 240, the social_id column
types differ between tables, with one as BIGINT and another as VARCHAR(500). To
fix this, choose a single consistent data type for social_id across all tables,
such as VARCHAR(255) or BIGINT, and update the column definitions accordingly to
ensure uniformity and prevent implicit type conversions.

Comment on lines +1 to +6
-- MySQL dump 10.13 Distrib 8.4.4, for macos15.2 (arm64)
--
-- Host: upbrella-production-db.ccjiaacly7wf.ap-northeast-2.rds.amazonaws.com Database: upbrella_prod
-- ------------------------------------------------------
-- Server version 8.0.40

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Include database creation and usage statements.
The script drops and recreates tables but doesn’t explicitly ensure the upbrella_prod database exists or switch to it. Add a CREATE DATABASE IF NOT EXISTS upbrella_prod; and USE upbrella_prod; at the top to guarantee context.

🤖 Prompt for AI Agents
In src/main/resources/db/init.sql at the beginning of the file (lines 1 to 6),
the script lacks explicit statements to create the database if it doesn't exist
and to switch to it. Add a `CREATE DATABASE IF NOT EXISTS upbrella_prod;`
statement followed by a `USE upbrella_prod;` statement at the top of the file to
ensure the database context is set before any table operations.

Comment on lines +49 to +55
`id` int NOT NULL AUTO_INCREMENT,
`store_meta_id` int DEFAULT NULL,
`date` varchar(45) DEFAULT NULL,
`open_at` time DEFAULT NULL,
`close_at` time DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=391 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add foreign key and index on store_meta_id.
business_hour.store_meta_id links to store_meta(id) but lacks an explicit FOREIGN KEY constraint and index. Define:

INDEX idx_business_hour_store_meta (store_meta_id),
FOREIGN KEY (store_meta_id) REFERENCES store_meta(id)

to enforce referential integrity and improve query performance.

🤖 Prompt for AI Agents
In src/main/resources/db/init.sql around lines 49 to 55, the business_hour table
defines store_meta_id without a foreign key constraint or index. Add an index on
store_meta_id named idx_business_hour_store_meta and define a foreign key
constraint referencing store_meta(id) to enforce referential integrity and
optimize queries. Update the table definition to include these after the column
definitions but before the closing parenthesis.

Comment on lines +181 to +183
`store_detail_id` int DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=60 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add foreign key and index on store_detail_id.
store_image.store_detail_id should be indexed and constrained:

INDEX idx_store_image_detail (store_detail_id),
FOREIGN KEY (store_detail_id) REFERENCES store_detail(id)

to maintain referential integrity.

🤖 Prompt for AI Agents
In src/main/resources/db/init.sql around lines 181 to 183, add an index and a
foreign key constraint on the store_detail_id column in the store_image table.
Modify the table definition to include INDEX idx_store_image_detail
(store_detail_id) and FOREIGN KEY (store_detail_id) REFERENCES store_detail(id)
to ensure referential integrity and improve query performance.

Comment on lines +238 to +244
`name` varchar(255) DEFAULT NULL,
`phone_number` varchar(255) DEFAULT NULL,
`social_id` varchar(500) DEFAULT NULL,
`bank` varchar(500) DEFAULT NULL,
`account_number` varchar(500) DEFAULT NULL,
`email` varchar(500) DEFAULT NULL,
PRIMARY KEY (`id`)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add unique constraints and indices on key columns.
Critical columns like email, social_id, and phone_number are often used to identify a user. Define unique indexes:

UNIQUE INDEX uq_user_email (email),
UNIQUE INDEX uq_user_social (social_id),
INDEX idx_user_phone (phone_number)

to enforce uniqueness and speed up lookups.

🤖 Prompt for AI Agents
In src/main/resources/db/init.sql around lines 238 to 244, add unique
constraints and indexes on the email, social_id, and phone_number columns to
enforce uniqueness and improve query performance. Specifically, add UNIQUE INDEX
uq_user_email on email, UNIQUE INDEX uq_user_social on social_id, and a regular
INDEX idx_user_phone on phone_number within the table definition.

Comment on lines +220 to +225
`store_meta_id` int DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`etc` varchar(255) DEFAULT NULL,
`missed` tinyint DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=209 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add foreign key and index on store_meta_id.
umbrella.store_meta_id should reference store_meta(id):

INDEX idx_umbrella_store_meta (store_meta_id),
FOREIGN KEY (store_meta_id) REFERENCES store_meta(id)

to enforce referential integrity.

🤖 Prompt for AI Agents
In src/main/resources/db/init.sql around lines 220 to 225, add an index and a
foreign key constraint on the store_meta_id column. Modify the table definition
to include INDEX idx_umbrella_store_meta (store_meta_id) and FOREIGN KEY
(store_meta_id) REFERENCES store_meta(id) to enforce referential integrity
between umbrella.store_meta_id and store_meta.id.

Comment on lines +107 to +108
`bank` varchar(45) DEFAULT NULL,
`account_number` varchar(45) DEFAULT NULL,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Align bank and account_number column types across tables.
history.bank and history.account_number use VARCHAR(45), whereas user.bank and user.account_number are VARCHAR(500). Choose consistent length/type to prevent truncation or waste.

Also applies to: 241-242

🤖 Prompt for AI Agents
In src/main/resources/db/init.sql around lines 107-108 and 241-242, the column
types for `bank` and `account_number` are inconsistent between the `history` and
`user` tables, with lengths of VARCHAR(45) and VARCHAR(500) respectively. To fix
this, choose a consistent VARCHAR length for both columns across all tables,
either by increasing the length in `history` to 500 or reducing the length in
`user` to 45, and update the column definitions accordingly to ensure uniformity
and prevent data issues.

Comment on lines +145 to +147
`store_meta_id` int DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add foreign key and index on store_meta_id.
locker.store_meta_id should reference store_meta(id) and be indexed:

INDEX idx_locker_store_meta (store_meta_id),
FOREIGN KEY (store_meta_id) REFERENCES store_meta(id)

to ensure referential integrity.

🤖 Prompt for AI Agents
In src/main/resources/db/init.sql around lines 145 to 147, the table definition
for locker lacks a foreign key constraint and index on the store_meta_id column.
Add an index named idx_locker_store_meta on store_meta_id and define a foreign
key constraint on store_meta_id referencing store_meta(id) to enforce
referential integrity. Include these definitions before the closing parenthesis
of the table schema.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/main/kotlin/upbrella/be/config/DevCorsConfig.kt (2)

14-31: CORS configuration looks good with a suggestion for improvement.

The CORS configuration is well-implemented with appropriate security measures:

  • Specific allowed origins (good security practice)
  • Comprehensive HTTP methods for REST API
  • Credentials enabled for authentication
  • Reasonable preflight cache duration

Consider externalizing the origins to application properties for better maintainability:

-            .allowedOrigins(
-                "http://localhost:3000",
-                "https://upbrella-front.vercel.app"
-            )
+            .allowedOriginPatterns(corsProperties.allowedOrigins.toTypedArray())

This would allow configuration via application-dev.yml:

cors:
  allowed-origins:
    - "http://localhost:3000"
    - "https://upbrella-front.vercel.app"

28-29: Security note: Review CORS settings for production.

The permissive header configuration (allowedHeaders("*")) and credentials enabled are appropriate for development. Ensure production CORS configuration is more restrictive if needed.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02bfef5 and 781ba70.

📒 Files selected for processing (2)
  • src/main/kotlin/upbrella/be/config/DevCorsConfig.kt (1 hunks)
  • src/main/resources/application-dev.yml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/main/resources/application-dev.yml
🔇 Additional comments (2)
src/main/kotlin/upbrella/be/config/DevCorsConfig.kt (2)

3-7: LGTM! Appropriate imports for CORS configuration.

All imports are necessary and correctly used for implementing WebMvcConfigurer-based CORS configuration.


10-12: Excellent refactoring to WebMvcConfigurer!

The migration from a custom Filter to WebMvcConfigurer is a best practice for CORS configuration in Spring. The profile-specific configuration ensures this only applies in the development environment.

@Gwonwoo-Nam Gwonwoo-Nam merged commit 8cef33f into dev May 24, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants