# Migration Matrix

Use this matrix after inventory. Confirm exact current v7 fields against `.ai-rules/jianghu-init-json-app/` instead of treating this document as a schema reference.

## 1. Choose the migration class

| Current state | Preferred target | Stop or preserve when |
|---|---|---|
| v2/v4/v6 semantic table/form init-json | v7 CRUD | Existing behavior cannot be represented without losing custom composition |
| Hand-maintained standard table/form HTML | v7 CRUD | Data, resources, methods, or page identity are still unknown |
| Hand-maintained dashboard/workspace HTML | v7 UI | The HTML is generated by another source or depends on undocumented runtime injection |
| Separate PC/mobile pages for one workflow | One v7 Page with both targets | Routes, page IDs, permissions, or business behavior are intentionally separate |
| Legacy component with embedded CRUD | v7 CRUD component plus host resources | No host page can own the required resources or runtime page identity differs |
| Current v7 page with deprecated fields | Narrow v7 cleanup | Compiler compatibility or downstream consumers still require the fields |

Do not migrate unrelated files for consistency. Keep a working legacy page when evidence is insufficient.

## 2. CRUD or UI target

Choose v7 CRUD when all are substantially true:

- The primary workflow is list/search/filter/create/update/delete.
- Fields and forms can be expressed semantically.
- Custom behavior is limited to supported slots, actions, or target overrides.
- Data and resource mappings are known.

Choose v7 UI when any dominant requirement is true:

- The page is a dashboard, detail workspace, editor, chart composition, or multi-stage workflow.
- DOM/component hierarchy is the primary behavior.
- Large custom regions cannot be represented by CRUD slots without recreating the whole page.
- List/form semantics would conceal rather than clarify the source.

Use CRUD with slots or overrides when the base workflow is CRUD and only isolated regions are custom.

## 3. Identity mapping

| Legacy concept | V7 direction | Required verification |
|---|---|---|
| Page `pageId` | `page.id` | Routes, menu entries, links, `_page`, `_resource`, and runtime calls still resolve |
| Page name/title | `page.name` or current v7 equivalent | Generated title and navigation remain correct |
| Component `componentPath` | `component.path` | Host include/import and generated component path remain compatible |
| Mobile page ID | Target runtime identity | Confirm compiler mobile ID behavior before merging or deleting the old page |
| Page menu flag | Current `page.menu` semantics | Layout height and navigation behavior remain correct |

Do not rename identities as part of migration unless explicitly requested.

## 4. Page type and targets

| Legacy shape | V7 direction |
|---|---|
| `jh-page` PC page | `jh-page` with PC target |
| `jh-mobile-page` paired with the same workflow | `jh-page` with both targets after equivalence is proven |
| Standalone mobile-only route | `jh-page` with mobile target if supported without changing route identity |
| `jh-component` legacy component | v7 `jh-component` with `component.path` |

Use `platform.pc/mobile` for Table/List and Drawer/Sheet policy. Use `pc()`/`mobile()` for structural target differences. Keep separate pages when business behavior or routing differs.

## 5. Data mapping

| Legacy evidence | V7 destination | Check |
|---|---|---|
| Table/model declaration | `dataSource` | Table/model exists and primary key is correct |
| Table headers | `fields` plus list columns | Keys, labels, formatting, slots, sortable/filter behavior |
| Form item lists | `fields` plus create/update fields or tabs | Required, readonly, rules, options, defaults, target differences |
| Search/filter controls | list search/filter configuration | Request operators and server/client filtering remain equivalent |
| Pagination flags | list pagination configuration | Request parameters, total count, scrolling, and mobile behavior |
| Custom requests | service/resource configuration or supporting methods | Permissions, hooks, response shape, and errors remain intact |

Do not infer writable fields solely from visible columns.

## 6. Action mapping

For every legacy action, record:

- Visible label and icon.
- Trigger location: toolbar, row, form, tab, dialog, or custom slot.
- Actual method or resource action.
- Confirmation, visibility, disabled, and loading behavior.
- PC/mobile availability.

Map business actions to non-empty `label + uiAction`. Use the current method name for custom actions when that method remains the runtime contract. Do not mechanically translate `intent`, `id`, or `actionId` without tracing the called behavior.

Structural action entries such as spacer, slot, and filter remain structural entries and do not require business-action fields.

## 7. Component resources and props

- Move legacy component identity to `component.path`.
- Put Vue props under `common.props` according to current v7 component rules.
- Remove component `page.id` and `resourceList` only after the host Page is confirmed to provide runtime identity and register permissions.
- Preserve host-to-component prop names and emitted events.
- Verify embedded height and list scrolling in the host layout.

## 8. Custom template behavior

| Behavior | Preferred v7 mechanism |
|---|---|
| Custom list cell | Supported list slot |
| Custom form section | Supported form slot or tab structure |
| Target-specific local template | Target slot |
| Different PC/mobile composition | `pc()` / `mobile()` override |
| Entire custom workspace | UI mode `pageContent` / `actionContent` |
| Shared reusable HTML | Existing include/component if still compatible |

Avoid copying a full generated HTML page into a string field. Preserve semantic ownership whenever possible.

For an embedded component, compare the migration input, active generated HTML, and active host together. A Drawer/Sheet/Dialog present only in generated HTML is still active behavior. If the host mounts the component directly, keep that structural container in v7 `actionContent`; moving only its body into `pageContent` changes initial visibility and is not equivalent.

V7 structural keys generate action/state/method names. When a legacy public action such as `viewX` also needs extra requests:

1. Prefer a structural key whose generated names do not collide with the public action, then let the public custom action call the generated open method plus its extra business steps; or
2. Rename the host action and verify every caller.

Inspect generated output to prove there is exactly one switch case and one method definition for each action/method name.

## 9. Stop conditions

Pause migration and report the blocker when:

- The active page ID, route, or source of truth cannot be determined.
- Required database fields or service/resource contracts are unknown.
- PC/mobile pages appear similar but have different permissions or mutation behavior.
- Generated HTML contains maintained behavior absent from init-json and its origin is unclear.
- Compilation requires a production database or destructive synchronization without authorization.
- Existing runtime behavior cannot be expressed by the current v7 compiler without a compiler change.
