-
Notifications
You must be signed in to change notification settings - Fork 37
fix: Modify the default values of table fields and page API #218
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
Conversation
WalkthroughThis update modifies database schema files for both H2 and MySQL by making the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant PageServiceImpl
participant PostSaveHook (optional)
Client->>PageServiceImpl: createPage() / updatePage()
PageServiceImpl->>PageServiceImpl: Save Page & PageHistory
alt postSaveHook present
PageServiceImpl->>PostSaveHook (optional): afterSave(Page)
end
PageServiceImpl-->>Client: Return result
Poem
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. ✨ 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: 0
♻️ Duplicate comments (1)
app/src/main/resources/sql/h2/create_all_tables_ddl_v1.h2.sql (1)
25-26
: Duplicate: nullabletenant_id
in H2 schema creation
This mirrors the change in the MySQL schema—tenant_id
is now nullable in every table. Please refer to the comments on the MySQL script to ensure consistency in application handling, index semantics, and documentation.Also applies to: 46-47, 52-53, 102-103, 123-124, 143-144, 161-162, 201-202, 240-241, 276-277, 306-307, 336-337, 367-368, 394-395, 433-434, 504-505, 541-542, 567-568, 625-626
🧹 Nitpick comments (2)
app/src/main/resources/sql/h2/update_all_tables_ddl.sql (2)
8-8
: Add rationale for makingpublish_url
nullable
Allowingpublish_url
to be NULL is fine for backward compatibility, but consider adding a brief inline comment above this DDL change to explain why it’s now optional (e.g., legacy records or deferred publishing). This will help future maintainers understand the intent.
10-29
: Verify application behavior with NULLtenant_id
The NOT NULL constraint ontenant_id
is being dropped across many tables. Please ensure:
- The Java data-access layer and any ORM mappings properly handle
tenant_id IS NULL
.- Queries and unique indexes still behave as expected when
tenant_id
is NULL (MySQL/ H2 treat NULLs as distinct).- New unit/integration tests cover both null and non-null tenant scenarios.
Would you like assistance generating those tests or verifying index behavior?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
app/src/main/resources/sql/h2/create_all_tables_ddl_v1.h2.sql
(20 hunks)app/src/main/resources/sql/h2/update_all_tables_ddl.sql
(1 hunks)app/src/main/resources/sql/mysql/create_all_tables_ddl_v1.mysql.sql
(20 hunks)app/src/main/resources/sql/mysql/update_all_tables_ddl.sql
(1 hunks)base/src/main/java/com/tinyengine/it/common/handler/MyMetaObjectHandler.java
(0 hunks)base/src/main/java/com/tinyengine/it/service/app/impl/PageServiceImpl.java
(4 hunks)base/src/main/java/com/tinyengine/it/service/extend/PostSaveHook.java
(1 hunks)base/src/test/java/com/tinyengine/it/common/handler/MyMetaObjectHandlerTest.java
(1 hunks)
💤 Files with no reviewable changes (1)
- base/src/main/java/com/tinyengine/it/common/handler/MyMetaObjectHandler.java
🔇 Additional comments (8)
base/src/test/java/com/tinyengine/it/common/handler/MyMetaObjectHandlerTest.java (1)
39-39
: Test updated to match implementation changes.The test expectation has been correctly reduced from 8 to 5 calls to
hasSetter
, which aligns with the removal of "tenantId", "renterId", and "siteId" field filling in theMyMetaObjectHandler
class.base/src/main/java/com/tinyengine/it/service/extend/PostSaveHook.java (1)
13-29
: Well-designed extension point for post-save operations.This interface provides a clean extension mechanism for actions that need to occur after saving a page. The interface follows single responsibility principle with appropriate documentation.
base/src/main/java/com/tinyengine/it/service/app/impl/PageServiceImpl.java (4)
47-47
: LGTM: Appropriate import for the new hook.
140-144
: Well-implemented optional dependency injection.The PostSaveHook is properly autowired with
required = false
, making it optional and preventing application startup failures if no implementation is provided.
284-286
: Good defensive programming when invoking the hook.The implementation checks for null before invoking the hook, ensuring no NullPointerException occurs when no hook implementation is provided.
378-380
: Consistent implementation in both save operations.The hook invocation is consistently implemented in both create and update operations, maintaining code symmetry.
app/src/main/resources/sql/mysql/update_all_tables_ddl.sql (1)
10-29
:❓ Verification inconclusive
Verify business impact of making tenant_id nullable.
The changes correctly modify the
tenant_id
column across multiple tables to be nullable. This is a significant schema change that aligns with the removal of tenant_id auto-filling inMyMetaObjectHandler
.However, this may have business logic implications:
- Are there any downstream processes that assume tenant_id is always present?
- Does this affect multi-tenancy security or data isolation?
- Will existing code handle null tenant_id values properly?
🏁 Script executed:
#!/bin/bash # Search for places where tenant_id is used without null checks echo "Searching for code that might assume tenant_id is non-null:" echo "--------------------------------------------------------" # Find queries that filter by tenant_id without checking for null echo "SQL queries or conditions using tenant_id:" rg -A 2 -B 2 "tenant_id\s*=|tenant_id\s*==|\.eq\(\s*[\"']tenant_id[\"']\s*," --type java # Find places where tenant_id is accessed directly (might need null checks) echo "Direct tenant_id access that might need null checks:" rg -A 2 -B 2 "\.getTenantId\(\)" --type java # Check service implementations for tenant_id usage echo "Service implementations using tenant_id:" rg -A 5 -B 5 "tenant_id" --type java --glob "*ServiceImpl.java"Length of output: 756
🏁 Script executed:
#!/bin/bash echo "Searching for 'tenantId' in Java sources:" rg -n "tenantId" --type java echo echo "Searching for QueryWrapper.eq or eq methods with TenantId arguments:" rg -n "eq\s*\(\s*.*TenantId" --type java echo echo "Searching for @Column annotation referencing tenant_id:" rg -n "@Column.*tenant_id" --type java echo echo "Searching for 'tenantId' in XML mapper files:" rg -n "tenantId" -g "*.xml"Length of output: 14461
Verify multi-tenancy behavior when
tenant_id
is null
Now thattenant_id
is nullable and auto-filling has been removed, all MyBatis mappers will skip theAND tenant_id = …
clause whenevertenantId
isnull
or empty—potentially returning data across all tenants. Please confirm that this aligns with your business and security requirements:• In
*.xml
mappers (e.g.PageMapper.xml
,UserMapper.xml
, etc.), each<if test="tenantId!=null and tenantId!=''">
block will be bypassed for null values, dropping tenant isolation.
• There is no additional null‐check logic in Java (noeq("tenantId", …)
calls nor directgetTenantId()
usages that enforce non-null).
• Tests (e.g.MyMetaObjectHandlerTest
) and entity mappings (via@Schema
and<result column="tenant_id" property="tenantId"/>
) will still function, but may now propagate nulltenantId
into DTOs and responses.• Do downstream services, APIs or UIs expect
tenantId
to always be present?
• Should queries with nulltenantId
default to an empty result set or raise an error instead of returning all rows?
• Are there any security audits or monitoring you need to add around null tenancy contexts?Please review and adjust the SQL conditions or service logic as needed to maintain proper data isolation.
app/src/main/resources/sql/mysql/create_all_tables_ddl_v1.mysql.sql (1)
25-26
: Maketenant_id
nullable in all MySQL create scripts
You’ve removed theNOT NULL
constraint ontenant_id
for every table. Please verify:
- All migration paths and the application layer expect and handle NULL tenant IDs correctly.
- Unique indexes that include
tenant_id
still enforce uniqueness as intended in MySQL (multiple NULLs allowed).- Documentation, entity definitions, and test suites are updated to reflect that
tenant_id
can now be NULL.Also applies to: 52-53, 102-103, 123-124, 143-144, 161-162, 201-202, 240-241, 276-277, 306-307, 336-337, 367-368, 394-395, 433-434, 504-505, 541-542, 567-568, 625-626
English | 简体中文
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Background and solution
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
Database Changes
tenant_id
field is now optional (nullable) in multiple tables across both H2 and MySQL databases.Chores
Tests