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).
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.
## 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)
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 main2026-10-15 20:36:21 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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
projects.level(family | product | component, products only) andprojects.parent_id.(tenant_id, parent_id) → projects(tenant_id, id): the parent stays in the tenant; deleting a project with children is refused.product.POST/PATCH /v1/tenants/{id}/projects[/{pid}]):levelandparent_id(""detaches).invalid_level,invalid_parent,too_deep,has_children(409 on delete, or turning a parent into a topic).kindis unchanged. Clients without the hierarchy getlevel: productat the top.GET …/projectsstays a flat list withlevel/parent_id(the portal groups by project id).openapi.yamlupdated.Next (not in this PR)
Tested
TestProjects_hierarchyon memory and Postgres:🤖 Generated with Claude Code