Skip to content

Conversation

@msslulu
Copy link
Contributor

@msslulu msslulu commented Dec 29, 2025

English | 简体中文

PR

1.update : app/src/main/resources/sql/h2/init_data_for_test_v1.0.0.sql
app/src/main/resources/sql/mysql/init_data_for_test_v1.0.0.sql
docker-deploy-data/mysql/init/init_data_for_test_v1.0.0.sql
t_tenant 表数据
2.add : app/src/main/resources/sql/mysql/09_update_table_ddl_2025_1229.sql ,
app/src/main/resources/sql/h2/09_update_table_ddl_2025_1229.sql
docker-deploy-data/mysql/init/09_update_table_ddl_2025_1229.sql
(update t_tenant INDEX,MODIFY COLUMN name_en,MODIFY COLUMN name_cn NULL)

3.update: rename app/src/main/resources/sql/h2,docker-deploy-data/mysql/init,app/src/main/resources/sql/mysql 目录下sql 文件名字,确保部署脚本顺序执行
4.修改TenantServiceImpl createTenant方法
5.修改GlobalExceptionAdvice 异常返回200(前端要求返回200)

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced bilingual support for organization naming with separate English and Chinese fields
    • Added resource hashing functionality
  • Bug Fixes

    • Corrected HTTP response status codes for error handling
    • Fixed organization uniqueness validation to use English name field
  • Chores

    • Database schema migrations and updates across multiple versions
    • Test data alignment with new schema structure

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 29, 2025

Walkthrough

This pull request updates database migration scripts across H2, MySQL, and Docker deployment configurations. Key changes include reformatting SQL files, schema modifications to the t_tenant table (index restructuring and column constraints), addition of a hash column to t_resource, updates to tenant initialization data, and adjustments to Java service logic for uniqueness checks and HTTP exception handling.

Changes

Cohort / File(s) Summary
SQL Formatting & Schema Migrations (H2)
app/src/main/resources/sql/h2/02_create_model_ddl_2025_0717.sql, 03_create_resources_ddl_2025_0902.sql, 04_create_permission_table_ddl_2025_1029.sql, 05_update_all_tables_ddl.sql, 06_update_tables_ddl_v1.0.0_2025_0527.sql
Whitespace and formatting adjustments; no semantic DDL changes.
H2 t_user Column Modifications
app/src/main/resources/sql/h2/07_update_table_ddl_2025_1014.sql
Removed bulk column drop from t_user; preserved subsequent column additions as individual ALTER statements. Reformatted for clarity.
H2 t_resource & t_tenant Schema Updates
app/src/main/resources/sql/h2/08_update_table_ddl_2025_1217.sql, 09_update_table_ddl_2025_1229.sql
Adds hash column (VARCHAR(100)) to t_resource; restructures t_tenant index from multi-column to single-column (name_en) unique constraint; updates column definitions and comments for t_tenant.name_en and t_tenant.name_cn.
SQL Formatting & Schema Migrations (MySQL)
app/src/main/resources/sql/mysql/02_create_model_ddl_2025_0717.sql, 03_create_resources_ddl_2025_0902.sql, 04_create_permission_table_ddl_2025_1029.sql, 05_update_all_tables_ddl.sql, 06_update_tables_ddl_v1.0.0_2025_0527.sql
Whitespace and formatting adjustments; no semantic DDL changes.
MySQL Schema & Index Updates
app/src/main/resources/sql/mysql/07_update_table_ddl_2025_1014.sql
Introduces new columns (is_template, industry_id, scene_id in t_app; business_group in t_business_category; platform_id in t_app_extension and t_model; app_id in t_model); restructures composite indexes for t_app, t_datasource, t_app_extension, and t_model; removes bulk column drop from t_user, preserving individual column additions.
MySQL t_resource & t_tenant Updates
app/src/main/resources/sql/mysql/08_update_table_ddl_2025_1217.sql, 09_update_table_ddl_2025_1229.sql
Adds hash column to t_resource; modifies t_tenant index to unique constraint on name_en and updates column definitions with comments.
Docker Deployment SQL Files
docker-deploy-data/mysql/init/02_create_model_ddl_2025_0717.sql, 03_create_resources_ddl_2025_0902.sql, 04_create_permission_table_ddl_2025_1029.sql, 05_update_all_tables_ddl.sql, 06_update_tables_ddl_v1.0.0_2025_0527.sql
Formatting adjustments and schema restructuring; t_model redesigned with bilingual name columns (name_cn, name_en) replacing single name field, adding model_url, and updating unique index.
Docker Deployment t_user & t_tenant Updates
docker-deploy-data/mysql/init/07_update_table_ddl_2025_1014.sql, 08_update_table_ddl_2025_1217.sql, 09_update_table_ddl_2025_1229.sql
Removes bulk t_user column drop; adds hash column to t_resource; restructures t_tenant index and column constraints.
Test Data Initialization
app/src/main/resources/sql/h2/init_data_for_test_v1.0.0.sql, app/src/main/resources/sql/mysql/init_data_for_test_v1.0.0.sql, docker-deploy-data/mysql/init/init_data_for_test_v1.0.0.sql
Swapped name_cn and name_en values in t_tenant INSERT statement (from 'public', '公共租户' to '公共租户', 'public').
Java Exception Handling
base/src/main/java/com/tinyengine/it/common/exception/GlobalExceptionAdvice.java
Updated HTTP response status for handleException(Exception) and handleServiceException(ServiceException) from INTERNAL_SERVER_ERROR to OK.
Java Tenant Service Logic
base/src/main/java/com/tinyengine/it/service/platform/impl/TenantServiceImpl.java
Modified createTenant uniqueness check to query by name_en (English name) instead of name_cn.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Hops through SQL with schema in hand,
Bilingual names now bravely stand,
Indexes shuffled, columns reformed,
Tenant and resource tables transformed!
A hash in sight, exceptions in light,
Database migrations done just right! 🌿✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'fix:update sql file,fix bug' is vague and generic; it uses non-descriptive terms like 'fix bug' without specifying which bug or what the actual changes accomplish. Replace with a specific, descriptive title that clearly indicates the main changes, such as 'refactor: Update t_tenant schema and init data for bilingual support' or 'fix: Correct tenant name field mappings in DDL and test data'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
base/src/main/java/com/tinyengine/it/common/exception/GlobalExceptionAdvice.java (3)

43-49: Critical: HTTP 200 OK for exceptions violates HTTP semantics.

Returning HttpStatus.OK for generic exceptions breaks HTTP standards and REST API conventions. Clients, monitoring tools, load balancers, and API gateways rely on status codes to detect failures.

Impact:

  • Clients cannot distinguish success from failure
  • Breaks automated error handling, retries, and circuit breakers
  • Monitoring/alerting systems won't detect failures
  • Makes production debugging difficult
🔎 Recommended fix
-    @ResponseStatus(HttpStatus.OK)
+    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
     @ExceptionHandler(Exception.class)
     public Result<Map<String, String>> handleException(Exception e) {
         // 修改为 log.error,传递异常对象以打印堆栈信息
         log.error("Exception occurred: ", e);
         return Result.failed(ExceptionEnum.CM001);
     }

72-78: Critical: HTTP 200 OK for business exceptions violates HTTP semantics.

ServiceException should return an appropriate 4xx or 5xx status code based on the error type, not 200 OK. This makes it impossible for clients and infrastructure to detect failures.

Consider:

  • 400 Bad Request for client errors
  • 422 Unprocessable Entity for validation failures
  • 500 Internal Server Error for server-side issues
🔎 Recommended fix (example with 400)
-    @ResponseStatus(HttpStatus.OK)
+    @ResponseStatus(HttpStatus.BAD_REQUEST)
     @ExceptionHandler(ServiceException.class)
     public Result<Map<String, String>> handleServiceException(ServiceException e) {
         // 修改为 log.error,传递异常对象以打印堆栈信息
         log.error("Business exception occurred: ", e);
         return Result.failed(e.getCode(), e.getMessage());
     }

Alternatively, map ServiceException error codes to appropriate HTTP status codes dynamically.


58-64: Existing handlers also return HTTP 200 for errors.

The handlers for NullPointerException (line 58) and MethodArgumentNotValidException (line 86) already use HttpStatus.OK, which has the same issues described above. Consider addressing these as well:

  • NullPointerException500 Internal Server Error
  • MethodArgumentNotValidException400 Bad Request

Also applies to: 86-95

♻️ Duplicate comments (1)
docker-deploy-data/mysql/init/07_update_table_ddl_2025_1014.sql (1)

33-33: Critical: Same data loss risk as H2 migration

This MySQL migration has the identical DROP COLUMN issue as the H2 version (app/src/main/resources/sql/h2/07_update_table_ddl_2025_1014.sql line 33). The data loss affects:

  • email column data (column is re-added but existing data will be lost)
  • tenant_id, site_id, renter_id, created_by, last_updated_by data (permanently lost)

Since this affects both database platforms, verify that:

  1. This is part of a coordinated deployment that includes data migration
  2. Production databases have proper backups before applying
  3. The deployment process is documented and tested
🧹 Nitpick comments (3)
app/src/main/resources/sql/mysql/08_update_table_ddl_2025_1217.sql (1)

1-2: Consider nullability constraint and indexing for the hash column.

The new hash column lacks an explicit NULL/NOT NULL constraint (will default to nullable) and has no index. Consider:

  1. Nullability: If hash is required for new resources, add NOT NULL and plan a backfill for existing rows.
  2. Indexing: If the hash is used for lookups or uniqueness checks, add an index to prevent full table scans.
🔎 Suggested improvements

If the hash should be required and indexed:

 ALTER TABLE t_resource
-    ADD COLUMN hash VARCHAR(100) AFTER thumbnail_url;
+    ADD COLUMN hash VARCHAR(100) NOT NULL AFTER thumbnail_url,
+    ADD INDEX idx_resource_hash (hash);

If it should be nullable but still indexed for performance:

 ALTER TABLE t_resource
-    ADD COLUMN hash VARCHAR(100) AFTER thumbnail_url;
+    ADD COLUMN hash VARCHAR(100) AFTER thumbnail_url,
+    ADD INDEX idx_resource_hash (hash);
docker-deploy-data/mysql/init/08_update_table_ddl_2025_1217.sql (1)

1-2: Schema change adds hash column to t_resource.

The column addition is consistent across MySQL and H2 environments. Consider adding a column comment to document the purpose of the hash field (e.g., for content deduplication or integrity verification).

🔎 Optional: Add column comment
 ALTER TABLE t_resource
-    ADD COLUMN hash VARCHAR(100) AFTER thumbnail_url;
+    ADD COLUMN hash VARCHAR(100) COMMENT '资源内容哈希值' AFTER thumbnail_url;
docker-deploy-data/mysql/init/09_update_table_ddl_2025_1229.sql (1)

1-5: Data migration validation recommended but existing controls mitigate risks

The schema changes shift the unique constraint from name_cn to name_en, making name_en NOT NULL. The original table definition shows name_en was previously nullable and name_cn held the unique index.

Risk assessment:

  • Test data contains no NULL or empty name_en values (verified: public tenant has name_en='public')
  • Application code in TenantServiceImpl.createTenant() already enforces name_en uniqueness via runtime check before insertion (lines 116-121)
  • Existing controls effectively mitigate the stated risks

Recommendation: While the migration appears safe given existing application constraints, consider adding a pre-migration validation step to explicitly verify there are no NULL/duplicate name_en values before running this DDL. This follows defensive migration best practices.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b688c67 and 3e7490b.

📒 Files selected for processing (32)
  • app/src/main/resources/sql/h2/01_create_all_tables_ddl_v1.0.0.h2.sql
  • app/src/main/resources/sql/h2/02_create_model_ddl_2025_0717.sql
  • app/src/main/resources/sql/h2/03_create_resources_ddl_2025_0902.sql
  • app/src/main/resources/sql/h2/04_create_permission_table_ddl_2025_1029.sql
  • app/src/main/resources/sql/h2/05_update_all_tables_ddl.sql
  • app/src/main/resources/sql/h2/06_update_tables_ddl_v1.0.0_2025_0527.sql
  • app/src/main/resources/sql/h2/07_update_table_ddl_2025_1014.sql
  • app/src/main/resources/sql/h2/08_update_table_ddl_2025_1217.sql
  • app/src/main/resources/sql/h2/09_update_table_ddl_2025_1229.sql
  • app/src/main/resources/sql/h2/init_data_for_test_v1.0.0.sql
  • app/src/main/resources/sql/mysql/01_create_all_tables_ddl_v1.0.0.mysql.sql
  • app/src/main/resources/sql/mysql/02_create_model_ddl_2025_0717.sql
  • app/src/main/resources/sql/mysql/03_create_resources_ddl_2025_0902.sql
  • app/src/main/resources/sql/mysql/04_create_permission_table_ddl_2025_1029.sql
  • app/src/main/resources/sql/mysql/05_update_all_tables_ddl.sql
  • app/src/main/resources/sql/mysql/06_update_tables_ddl_v1.0.0_2025_0527.sql
  • app/src/main/resources/sql/mysql/07_update_table_ddl_2025_1014.sql
  • app/src/main/resources/sql/mysql/08_update_table_ddl_2025_1217.sql
  • app/src/main/resources/sql/mysql/09_update_table_ddl_2025_1229.sql
  • app/src/main/resources/sql/mysql/init_data_for_test_v1.0.0.sql
  • base/src/main/java/com/tinyengine/it/common/exception/GlobalExceptionAdvice.java
  • base/src/main/java/com/tinyengine/it/service/platform/impl/TenantServiceImpl.java
  • docker-deploy-data/mysql/init/01_create_all_tables_ddl_v1.0.0.mysql.sql
  • docker-deploy-data/mysql/init/02_create_model_ddl_2025_0717.sql
  • docker-deploy-data/mysql/init/03_create_resources_ddl_2025_0902.sql
  • docker-deploy-data/mysql/init/04_create_permission_table_ddl_2025_1029.sql
  • docker-deploy-data/mysql/init/05_update_all_tables_ddl.sql
  • docker-deploy-data/mysql/init/06_update_tables_ddl_v1.0.0_2025_0527.sql
  • docker-deploy-data/mysql/init/07_update_table_ddl_2025_1014.sql
  • docker-deploy-data/mysql/init/08_update_table_ddl_2025_1217.sql
  • docker-deploy-data/mysql/init/09_update_table_ddl_2025_1229.sql
  • docker-deploy-data/mysql/init/init_data_for_test_v1.0.0.sql
🔇 Additional comments (18)
docker-deploy-data/mysql/init/05_update_all_tables_ddl.sql (1)

1-30: LGTM - Formatting-only change.

This file contains no semantic changes to the DDL statements. All ALTER TABLE commands remain functionally identical.

app/src/main/resources/sql/mysql/02_create_model_ddl_2025_0717.sql (1)

1-22: LGTM - Formatting adjustments only.

The changes are limited to whitespace and line formatting. The table schema, columns, constraints, and indexes remain semantically unchanged.

app/src/main/resources/sql/h2/06_update_tables_ddl_v1.0.0_2025_0527.sql (1)

1-2: LGTM - No functional change.

The diff shows a no-op replacement where the identical SQL statement is rewritten. No semantic impact.

app/src/main/resources/sql/mysql/06_update_tables_ddl_v1.0.0_2025_0527.sql (1)

1-2: LGTM - No functional change.

This is a no-op change where the statement is replaced with an identical copy. No semantic modifications.

app/src/main/resources/sql/mysql/05_update_all_tables_ddl.sql (1)

1-31: LGTM - Formatting-only change.

The only change is the addition of trailing newlines. All DDL statements remain functionally identical.

app/src/main/resources/sql/h2/02_create_model_ddl_2025_0717.sql (1)

1-22: LGTM - Formatting adjustments only.

The changes are limited to whitespace formatting. The table schema, including columns, constraints, and indexes, remains semantically unchanged.

app/src/main/resources/sql/h2/05_update_all_tables_ddl.sql (1)

1-29: LGTM - No semantic changes.

The changes only update line markers while preserving identical DDL content. No functional impact.

docker-deploy-data/mysql/init/06_update_tables_ddl_v1.0.0_2025_0527.sql (1)

1-2: Formatting change acknowledged.

No semantic changes to the DDL statements. The index modification correctly adds a composite index on (tenant_id, platform_id, name, app_id) for t_block_group.

app/src/main/resources/sql/mysql/04_create_permission_table_ddl_2025_1029.sql (1)

1-34: Formatting restructure with no semantic changes.

Table definitions for t_permission_role and r_auth_users_units_roles retain the same columns, constraints, and indexes. The reformatting improves readability.

app/src/main/resources/sql/h2/04_create_permission_table_ddl_2025_1029.sql (1)

1-34: Formatting restructure mirrors MySQL version.

Table definitions are consistent with the MySQL counterpart. The same H2 compatibility note applies regarding MySQL-specific syntax (engine = innodb).

app/src/main/resources/sql/mysql/03_create_resources_ddl_2025_0902.sql (1)

1-58: Formatting restructure with no semantic changes.

Table definitions for resource-related tables retain identical columns, constraints, and indexes. The reformatting improves consistency across the codebase.

base/src/main/java/com/tinyengine/it/service/platform/impl/TenantServiceImpl.java (1)

114-133: [rewritten review comment]
[classification tag]

app/src/main/resources/sql/h2/03_create_resources_ddl_2025_0902.sql (1)

27-27: Remove or replace MySQL-specific syntax in H2 DDL files.

The engine = innodb clause is MySQL-specific and unsupported by H2. This is a systemic issue found in 36+ instances across multiple H2 DDL files (01_create_all_tables_ddl_v1.0.0.h2.sql, 02_create_model_ddl_2025_0717.sql, 03_create_resources_ddl_2025_0902.sql, 04_create_permission_table_ddl_2025_1029.sql).

Additionally, other MySQL-specific syntax is present (e.g., USING BTREE in index definitions, auto_increment). H2 may silently ignore these clauses in compatibility mode, but this could fail in strict mode or cause issues during test execution. Either standardize all H2 DDL files to H2-compatible syntax, or verify that H2 is configured to tolerate MySQL syntax without errors.

app/src/main/resources/sql/h2/08_update_table_ddl_2025_1217.sql (1)

1-2: The AFTER clause is supported by H2 database in ALTER TABLE ADD COLUMN statements. This syntax has been available since H2 v1.3.171 and is documented in the official H2 command reference. The migration file requires no changes.

Likely an incorrect or invalid review comment.

docker-deploy-data/mysql/init/init_data_for_test_v1.0.0.sql (1)

4-4: Data migration aligns with schema changes - verify execution order

Line 4 swaps the name_cn and name_en values, changing from:

  • Old: (1, 'public', '公共租户', ...)
  • New: (1, '公共租户', 'public', ...)

This aligns with the schema changes in 09_update_table_ddl_2025_1229.sql which:

  • Makes name_en the unique identifier (NOT NULL + unique index)
  • Makes name_cn optional (NULL allowed)

Critical: Ensure migration scripts execute in this order:

  1. First: Schema changes (09_update_table_ddl_2025_1229.sql) OR data updates
  2. The order depends on whether this is a fresh init or updating existing data

For fresh deployments (init scripts), this is correct. For existing databases, you'll need an UPDATE script instead:

-- For migrating existing data
UPDATE t_tenant SET 
  name_en_temp = name_en,
  name_en = name_cn,
  name_cn = name_en_temp;

Verify: Is this init script only for new deployments, or does it need to handle existing data migration?

app/src/main/resources/sql/mysql/init_data_for_test_v1.0.0.sql (1)

4-4: Column order and semantic values in t_tenant INSERT are correct.

The test data correctly has Chinese text ('公共租户') in name_cn and English text ('public') in name_en, matching the column semantics. Column order in the INSERT statement matches the table schema definition. All three test environments (MySQL, H2, and Docker) have identical t_tenant data, ensuring consistency.

Note: The DDL changes in 09_update_table_ddl_2025_1229.sql swap which column is required (making name_en NOT NULL and name_cn nullable) and move the unique constraint from name_cn to name_en. Verify that any existing production data handles these schema constraint changes correctly.

app/src/main/resources/sql/h2/init_data_for_test_v1.0.0.sql (1)

4-4: LGTM - Test data correctly updated

The swap of name_en and name_cn values correctly aligns with the schema changes in the DDL files where name_en becomes the NOT NULL unique identifier.

docker-deploy-data/mysql/init/02_create_model_ddl_2025_0717.sql (1)

1-22: No migration script needed—t_model is a newly introduced table

The structural design with name_cn and name_en is correct for this fresh table introduction. Since t_model does not exist in the base schema (file 01), there is no existing data to migrate. File 02 creates the table with the bilingual columns from the start, and file 07 correctly extends the schema by adding app_id and platform_id columns.

The DROP TABLE IF EXISTS pattern in file 02 ensures idempotency for fresh installations. No migration of a single name column is required because the table is new to the codebase.

@lu-yg lu-yg merged commit 40b8cd2 into opentiny:develop Dec 29, 2025
1 check 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