Skip to content

refactor(meta): split MetaModelData model into application and model - #236

Merged
buke merged 6 commits into
mainfrom
refactor/meta-model-data-application-model
Aug 3, 2026
Merged

refactor(meta): split MetaModelData model into application and model#236
buke merged 6 commits into
mainfrom
refactor/meta-model-data-application-model

Conversation

@buke

@buke buke commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

User description

Summary

  • Split meta_model_data mapping target from a single full name (auth.User) into application + short model (E11 / PR-EID-4).
  • Seed JSON top-level and Go/TS facades follow the same shape; loader validates and resolves without top-level splitModel.
  • Value-level addressing (refBy / search / modelRef / serviceRef) still uses full app.Model; Ref/RefOrNull signatures stay module.nameres_id.

Test plan

  • go test ./internal/module/evolution/data/ ./internal/module/metadata/ ./internal/module/lifecycle/ ./internal/bootstrap/... -count=1
  • ./choysum test unit meta --be (after rebuild)
  • Wipe + reinstall auth/base bootstrap smoke (optional local)

Made with Cursor


PR Type

Enhancement


Description

  • Go core: Split ModelData mapping target into Application and short Model fields, updating loader validation rules.

  • TS modules: Added Application property to MetaModelData model and updated all module JSON seed records.

  • Testing & Compliance: Updated Go unit tests, TS unit tests, and E2E fixtures; no new files requiring SPDX headers.


File Walkthrough

Relevant files
Tests
8 files
coordinator_admin_coverage_test.go
Update admin seed ModelData test fixture with Application field
+1/-1     
loader_test.go
Update seed loader tests for application and model separation
+106/-84
translated_seed_test.go
Update translated seed tests with application and model fields
+2/-2     
uninstaller_model_data_test.go
Update uninstaller tests with application and short model name
+4/-4     
smoke.json
Update auth E2E fixture records to use application and model
+70/-25 
language_format.json
Update base language format E2E fixture record fields       
+5/-2     
smoke.json
Update meta E2E smoke fixture to use application and model
+2/-1     
model_data_ref.test.ts
Update TS unit test mock data store with Application field
+5/-5     
Refactoring
2 files
loader.go
Validate record application and short model name during seed loading
+86/-36 
translated_seed.go
Check application and short model name for language translation seed
+7/-1     
Enhancement
2 files
model_data.go
Add Application field and compound index to ModelData struct
+6/-5     
model_data.ts
Add Application field decorator to MetaModelData class     
+3/-0     
Configuration changes
3 files
bootstrap.json
Split model into application and model in auth bootstrap seed
+451/-131
bootstrap.json
Split model into application and model in base bootstrap seed
+14/-6   
demo.json
Update base demo JSON record to split model field               
+2/-1     

Summary by CodeRabbit

  • New Features
    • Model metadata now records the application and model name separately.
    • Bootstrap and fixture records support explicit applications with unqualified model names.
    • Added a child-company end-to-end scenario.
  • Bug Fixes
    • Improved validation, ownership checks, reference resolution, dependency handling, and persistence consistency.
    • Errors now identify application context and detect missing or mismatched applications.
    • Updated administrative, demo, language, and metadata records to use the corrected format.

- Store mapping targets as application plus short model name, aligned with meta_model.

- Update loader seed schema and reject top-level full-name model forms without a compatibility window.

- Keep refBy/search/modelRef addressing as app.Model; leave Ref(xml_id) unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 8 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: db76fee1-04fa-48fc-a1d8-9e80f6a079b5

📥 Commits

Reviewing files that changed from the base of the PR and between b34e149 and 981ff0a.

📒 Files selected for processing (5)
  • internal/module/evolution/data/loader.go
  • internal/module/evolution/data/loader_test.go
  • internal/module/evolution/data/translated_seed.go
  • internal/module/evolution/data/translated_seed_coverage_test.go
  • modules/base/web/views/language_merge.mapping.test.ts
📝 Walkthrough

Walkthrough

The loader now requires separate application and short model fields. Metadata storage uses a composite application/model identity. Validation and errors preserve application context. Bootstrap data, fixtures, and related tests use the new representation.

Changes

Application/model identity

Layer / File(s) Summary
Identity contracts and error metadata
internal/module/metadata/model_data.go, modules/meta/service/models/model_data.ts, internal/module/evolution/data/loader.go
ModelData and MetaModelData now store a required indexed Application. Loader records use short model names, and LoadError preserves application context.
Validation, resolution, and persistence
internal/module/evolution/data/loader.go, internal/module/evolution/data/loader_test.go, internal/module/lifecycle/..., internal/bootstrap/...
Batch and single-file loading normalize ownership, validate application/model pairs, resolve references with both fields, reject qualified model names, and persist separate values.
Translated seed handling
internal/module/evolution/data/translated_seed.go, internal/module/evolution/data/translated_seed_test.go, modules/meta/service/tests/model_data_ref.test.ts
Translated seed errors include application metadata. Base language detection uses separate application and model fields.
Seed and fixture migration
modules/auth/..., modules/base/..., modules/meta/e2e/fixtures/smoke.json
Seed records and fixtures use short model names. References retain their existing targets and behavior. A child-company fixture is added to the default end-to-end scenario.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SeedRecord
  participant EvolutionLoader
  participant ModelData
  SeedRecord->>EvolutionLoader: application and short model
  EvolutionLoader->>ModelData: resolve application/model pair
  ModelData-->>EvolutionLoader: model mapping
  EvolutionLoader->>ModelData: persist separate application and model
Loading

Possibly related PRs

Suggested labels: Review effort 3/5

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: splitting the MetaModelData model target into application and model fields.
Description check ✅ Passed The description explains the changes, test plan, implementation details, affected areas, and remaining optional validation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/meta-model-data-application-model

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

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Comment thread internal/module/evolution/data/loader.go Outdated
Comment thread internal/module/evolution/data/loader.go Outdated
Comment thread internal/module/evolution/data/loader.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

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

⚠️ Outside diff range comments (1)
internal/module/evolution/data/loader.go (1)

1291-1309: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Pass the application-qualified model to detectSearchCardinality.

Without the explicit first-result hint, the short rec.Model makes cardinality detection fall back to ManyToOne. This rejects valid multi-result searches and converts single-result ManyToMany values to scalars. Use app + "." + modelName or the equivalent qualified identity from model.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/module/evolution/data/loader.go` around lines 1291 - 1309, Update
the detectSearchCardinality call in the values resolution loop to pass the
application-qualified model identity, such as app plus rec.Model or the
equivalent qualified model symbol, instead of the short rec.Model. Preserve the
existing fieldName and raw arguments so multi-result searches and single-result
ManyToMany values retain their correct cardinality.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/module/evolution/data/translated_seed.go`:
- Around line 201-202: The v == nil branch that constructs LoadError must
populate Application consistently with the neighboring validation errors, using
the trimmed application value from the translated seed record. Add or update a
test covering a nil translated value and assert that the resulting LoadError
retains Application.

In `@internal/module/metadata/model_data.go`:
- Around line 8-17: Update the ModelData schema and migration handling for the
new Application field so SQLite can migrate tables containing existing rows: add
a GORM default of an empty string or implement an explicit migration that safely
adds the column, then backfill existing Application values from authoritative
metadata. Keep Model unchanged and do not add it a default.

---

Outside diff comments:
In `@internal/module/evolution/data/loader.go`:
- Around line 1291-1309: Update the detectSearchCardinality call in the values
resolution loop to pass the application-qualified model identity, such as app
plus rec.Model or the equivalent qualified model symbol, instead of the short
rec.Model. Preserve the existing fieldName and raw arguments so multi-result
searches and single-result ManyToMany values retain their correct cardinality.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 91e0f05c-7ec0-4c74-b765-80b501768307

📥 Commits

Reviewing files that changed from the base of the PR and between c8a5296 and 0cf298d.

📒 Files selected for processing (15)
  • internal/bootstrap/service/coordinator_admin_coverage_test.go
  • internal/module/evolution/data/loader.go
  • internal/module/evolution/data/loader_test.go
  • internal/module/evolution/data/translated_seed.go
  • internal/module/evolution/data/translated_seed_test.go
  • internal/module/lifecycle/uninstaller_model_data_test.go
  • internal/module/metadata/model_data.go
  • modules/auth/data/bootstrap.json
  • modules/auth/e2e/fixtures/smoke.json
  • modules/base/data/bootstrap.json
  • modules/base/demo/demo.json
  • modules/base/e2e/fixtures/language_format.json
  • modules/meta/e2e/fixtures/smoke.json
  • modules/meta/service/models/model_data.ts
  • modules/meta/service/tests/model_data_ref.test.ts

Comment thread internal/module/evolution/data/translated_seed.go
Comment thread internal/module/metadata/model_data.go
- Omit module/application in seed JSON; loader fills them from the applying module (E12).

- Reject foreign xml_id namespaces and cross-app seeding; move auth e2e Company fixture to base.

Co-authored-by: Cursor <cursoragent@cursor.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
internal/module/evolution/data/loader.go (1)

685-701: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the shared normalize-and-validate preflight into one helper.

planBatchRecordOrder (685-701) and planRecordOrder (948-964) run the same sequence: call normalizeRecordOwnership, trim Module/Name, check for a missing name, call validateRecordTargetModel, then check for missing Values. The only difference is how FilePath/RecordIndex are sourced (batchRecord fields vs. plain filePath/idx). The corresponding test suites (TestPlanBatchRecordOrder_ValidationAndRefErrors, TestPlanRecordOrder_GuardsAndValidationErrors) already duplicate the same validation matrix to keep both paths in sync.

Extract a small helper, for example:

func preflightRecord(rules *moduleRules, filePath string, recordIndex int, rec *record) (app, modelName string, err error) {
	if err := normalizeRecordOwnership(rules, filePath, recordIndex, rec); err != nil {
		return "", "", err
	}
	moduleName := strings.TrimSpace(rec.Module)
	localName := strings.TrimSpace(rec.Name)
	if localName == "" {
		return "", "", &LoadError{Kind: LoadErrorKindValidation, Code: LoadErrorCodeMissingName, FilePath: filePath, RecordIndex: recordIndex, Module: moduleName, Message: "missing name"}
	}
	app, modelName, err = validateRecordTargetModel(filePath, recordIndex, *rec)
	if err != nil {
		return "", "", err
	}
	if rec.Values == nil {
		return "", "", &LoadError{Kind: LoadErrorKindValidation, Code: LoadErrorCodeMissingValues, FilePath: filePath, RecordIndex: recordIndex, Module: moduleName, Name: localName, Application: app, Model: modelName, Message: "missing values"}
	}
	return app, modelName, nil
}

Both call sites then reduce to a single call plus their own duplicate-key check, removing the duplicated validation logic without changing behavior.

Also applies to: 948-964

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/module/evolution/data/loader.go` around lines 685 - 701, Extract the
shared normalize-and-validate sequence from planBatchRecordOrder and
planRecordOrder into a preflightRecord helper accepting rules, filePath,
recordIndex, and *record, preserving all existing validation errors and
returning app/modelName. Replace both call-site blocks with the helper call,
retaining only each path’s own duplicate-key checks and sourcing file path/index
from its existing inputs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/module/evolution/data/loader.go`:
- Around line 685-701: Extract the shared normalize-and-validate sequence from
planBatchRecordOrder and planRecordOrder into a preflightRecord helper accepting
rules, filePath, recordIndex, and *record, preserving all existing validation
errors and returning app/modelName. Replace both call-site blocks with the
helper call, retaining only each path’s own duplicate-key checks and sourcing
file path/index from its existing inputs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 73363401-fa73-4ab3-be5d-8a206e70e666

📥 Commits

Reviewing files that changed from the base of the PR and between 0cf298d and 61190c4.

📒 Files selected for processing (10)
  • internal/module/evolution/data/loader.go
  • internal/module/evolution/data/loader_test.go
  • modules/auth/data/bootstrap.json
  • modules/auth/e2e/fixtures/smoke.json
  • modules/base/data/bootstrap.json
  • modules/base/demo/demo.json
  • modules/base/e2e/fixtures/company_child.json
  • modules/base/e2e/fixtures/language_format.json
  • modules/base/package.json
  • modules/meta/e2e/fixtures/smoke.json
💤 Files with no reviewable changes (5)
  • modules/base/e2e/fixtures/language_format.json
  • modules/meta/e2e/fixtures/smoke.json
  • modules/base/demo/demo.json
  • modules/auth/data/bootstrap.json
  • modules/base/data/bootstrap.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/module/evolution/data/loader_test.go

buke and others added 2 commits August 3, 2026 21:21
- Replace the short-name model column with model_id pointing at meta_model.

- Keep seed JSON short model for resolve; loader writes ModelId after lookup.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Expect short Language model names after MetaModelData target split.

- Assert language_zh_cn on company_child fixture after it left smoke.json.

Co-authored-by: Cursor <cursoragent@cursor.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@modules/meta/service/models/model_data.ts`:
- Around line 60-61: Update the ModelId field metadata in MetaModelData to
include notNull: true, matching the Go schema, while retaining the optional
property marker only for unloaded relations. Add a focused test that verifies
validation rejects a missing ModelId.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 928ad9e6-97d5-4e65-84c5-e3674d7232e7

📥 Commits

Reviewing files that changed from the base of the PR and between 61190c4 and b34e149.

📒 Files selected for processing (6)
  • internal/bootstrap/service/coordinator_admin_coverage_test.go
  • internal/module/evolution/data/loader.go
  • internal/module/evolution/data/loader_test.go
  • internal/module/lifecycle/uninstaller_model_data_test.go
  • internal/module/metadata/model_data.go
  • modules/meta/service/models/model_data.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • internal/module/lifecycle/uninstaller_model_data_test.go
  • internal/module/evolution/data/loader.go
  • internal/module/evolution/data/loader_test.go

Comment thread modules/meta/service/models/model_data.ts
- Build application.Model before detectSearchCardinality so ManyToMany seeds work.

- Fill Application on cycle and nil translated-map LoadErrors; sync mapping target on update.

Co-authored-by: Cursor <cursoragent@cursor.com>
@buke

buke commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit c0405c6. Configure here.

Comment thread internal/module/metadata/model_data.go
- Exercise ownership nil guards, LoadError model display, and recordModelFull fallbacks.

- Sync and fail stale application/model_id updates on existing mappings.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant