-
Notifications
You must be signed in to change notification settings - Fork 4
feat: init sql #496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: init sql #496
Conversation
|
""" WalkthroughA comprehensive MySQL initialization script was added, defining the schema for the Changes
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.)
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit 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. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 necessarySET NAMES utf8mb4and disabling foreign key/unique checks.
30-38: ResetAUTO_INCREMENTto 1 for a clean schema.
TheAUTO_INCREMENT=3on the newblack_listtable 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.
Usingtype(a MySQL keyword) as a column name can lead to confusion. Consider renaming toclassification_typeor similar.
69-70: Consider spatial data types for geolocation.
Storing latitude/longitude asDOUBLEworks, 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 forcontent.
UsingVARCHAR(401)is unconventional (odd limit) and may still truncate content if requirements change. Consider:
- Switching to
TEXTfor 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 columncountconflicts with the SQL aggregate function. Renaming it toquantityortotal_countimproves clarity and avoids potential parsing issues.
219-219: Review data type choice foruuid.
Storing UUIDs in a numericBIGINTmay not align with standard UUID formats. If using standard GUIDs, considerCHAR(36)orBINARY(16)foruuid.
232-233: Avoid reserved table names.
Naming the tableuser(a reserved keyword) can lead to confusion and quoting overhead. Consider renaming tousersorapp_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
📒 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 restoresSQL_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.
| `store_meta_id` int DEFAULT NULL, | ||
| `umbrella_location` varchar(255) DEFAULT NULL, | ||
| PRIMARY KEY (`id`) |
There was a problem hiding this comment.
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 '+'*/ ''; |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
| -- 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 | ||
|
|
There was a problem hiding this comment.
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.
| `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; |
There was a problem hiding this comment.
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.
| `store_detail_id` int DEFAULT NULL, | ||
| PRIMARY KEY (`id`) | ||
| ) ENGINE=InnoDB AUTO_INCREMENT=60 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; |
There was a problem hiding this comment.
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.
| `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`) |
There was a problem hiding this comment.
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.
| `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; |
There was a problem hiding this comment.
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.
| `bank` varchar(45) DEFAULT NULL, | ||
| `account_number` varchar(45) DEFAULT NULL, |
There was a problem hiding this comment.
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.
| `store_meta_id` int DEFAULT NULL, | ||
| PRIMARY KEY (`id`) | ||
| ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
📒 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.
🟢 구현내용
🧩 고민과 해결과정
Summary by CodeRabbit