feat(projects): product hierarchy - family, product, component #78

Merged
sharang merged 1 commits from feat/product-hierarchy into main 2026-10-15 20:36:21 +00:00
Owner

Why

Customers have product families and machines made of components (robot arm, sensors, PLC, edge server, Windows app). Today a product project is flat, so Werkmeister's auto-fill mixes component data sheets into the product's single answers (e.g. a component's firmware as the machine's firmware).

What

  • Migration 0020: projects.level (family | product | component, products only) and projects.parent_id.
    • FK (tenant_id, parent_id) → projects(tenant_id, id): the parent stays in the tenant; deleting a project with children is refused.
    • CHECK: topics have no level and no parent; a project is not its own parent.
    • Existing products → level product.
  • API (POST/PATCH /v1/tenants/{id}/projects[/{pid}]): level and parent_id ("" detaches).
    • A family sits at the top. A product sits below a family or nothing. A component sits below a product or a component (robot arm → gripper).
    • Same tenant, no cycles, at most 4 levels counting what hangs below. A level change must keep the children fitting.
    • Errors: invalid_level, invalid_parent, too_deep, has_children (409 on delete, or turning a parent into a topic).
  • kind is unchanged. Clients without the hierarchy get level: product at the top. GET …/projects stays a flat list with level/parent_id (the portal groups by project id).
  • A document's role follows the level of the project it's linked to; no document change.
  • openapi.yaml updated.

Next (not in this PR)

  • Werkmeister: product runs read the family's documents (inherited) and the components' (lists only, rows marked with their component).
  • Portal: parent/level picker and a product tree (production-go-live-plan, on the user's go).

Tested

  • TestProjects_hierarchy on memory and Postgres:
    • legacy default, nesting, the flat list;
    • every refusal: bad level, topic with level/parent, family below anything, component at the top, product below a product, component below a family or topic, unknown or foreign parent, too deep (also via the subtree), cycle, a level change breaking children, a parent turning into a topic;
    • detach, rename keeps the place, a leaf becomes a topic;
    • delete with children refused, leaves first.
  • Existing projects/documents tests and migrations up/down pass. golangci-lint clean.

🤖 Generated with Claude Code

## Why Customers have product families and machines made of components (robot arm, sensors, PLC, edge server, Windows app). Today a product project is flat, so Werkmeister's auto-fill mixes component data sheets into the product's single answers (e.g. a component's firmware as the machine's firmware). ## What - **Migration 0020:** `projects.level` (family | product | component, products only) and `projects.parent_id`. - FK `(tenant_id, parent_id) → projects(tenant_id, id)`: the parent stays in the tenant; deleting a project with children is refused. - CHECK: topics have no level and no parent; a project is not its own parent. - Existing products → level `product`. - **API** (`POST/PATCH /v1/tenants/{id}/projects[/{pid}]`): `level` and `parent_id` (`""` detaches). - A family sits at the top. A product sits below a family or nothing. A component sits below a product or a component (robot arm → gripper). - Same tenant, no cycles, at most 4 levels counting what hangs below. A level change must keep the children fitting. - Errors: `invalid_level`, `invalid_parent`, `too_deep`, `has_children` (409 on delete, or turning a parent into a topic). - `kind` is unchanged. Clients without the hierarchy get `level: product` at the top. `GET …/projects` stays a flat list with `level`/`parent_id` (the portal groups by project id). - A document's role follows the level of the project it's linked to; no document change. - `openapi.yaml` updated. ## Next (not in this PR) - Werkmeister: product runs read the family's documents (inherited) and the components' (lists only, rows marked with their component). - Portal: parent/level picker and a product tree (production-go-live-plan, on the user's go). ## Tested - `TestProjects_hierarchy` on memory and Postgres: - legacy default, nesting, the flat list; - every refusal: bad level, topic with level/parent, family below anything, component at the top, product below a product, component below a family or topic, unknown or foreign parent, too deep (also via the subtree), cycle, a level change breaking children, a parent turning into a topic; - detach, rename keeps the place, a leaf becomes a topic; - delete with children refused, leaves first. - Existing projects/documents tests and migrations up/down pass. golangci-lint clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sharang added 1 commit 2026-10-15 20:10:17 +00:00
feat(projects): product hierarchy - family, product, component
ci / shared (pull_request) Successful in 14s
ci / test (pull_request) Successful in 25m43s
ci / image (pull_request) Skipped
c4b7686cc5
A product project gets a level (family | product | component) and a
parent (migration 0020), so a machine with its robot arm, PLC, edge
server and Windows app, or a product family, can be modelled. Topics stay
flat; kind is unchanged and old clients get level "product" at the top.
The API checks the tree: allowed parents per level, same tenant, no
cycles, at most 4 levels, children still fitting after a level change.
The database keeps parents within the tenant and refuses to delete a
project with children (409 has_children). The list stays flat with
level and parent_id. A document's role follows the level of the project
it is linked to; no document schema change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang merged commit 06ad8d9b55 into main 2026-10-15 20:36:21 +00:00
Sign in to join this conversation.