Skip to content

feat: Add Multi-Tenant Catalog With Closure Table And Money - #9

Merged
ThomasHartDev merged 2 commits into
mainfrom
thomas/feat/complex-schema
Sep 18, 2026
Merged

ThomasHartDev merged 2 commits into
mainfrom
thomas/feat/complex-schema

Conversation

@ThomasHartDev

Copy link
Copy Markdown
Owner

The catalog is the hard schema this repo was aiming at. Tenants, categories, a closure table, and products with integer money and a nullable deletedAt. Lookups go by (tenantId, id), so a category from another tenant is missing instead of attached. Reparent refuses a cycle by checking whether the new parent already sits in the subtree.

The DSL still emits single-column foreign keys, so same-tenant writes live in Catalog. Live SKU uniqueness is a partial unique index, which the DSL also cannot say, so applyCatalogSchema runs that CREATE UNIQUE INDEX after migrate. Money is minor units plus ISO 4217. allocateMoney uses largest remainder so a 100-unit split into three parts is 34, 33, 33.

Closes #8

Declare a catalog schema that uses composite (tenantId, id) identity,
a closure table for category trees, integer minor-unit money, and
soft delete with a partial unique index on live SKUs.
A null parent is a new forest root and cannot cycle. Binding
parentId ?? id matched the depth-0 self-edge and always threw.
@ThomasHartDev
ThomasHartDev merged commit 5da9485 into main Sep 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a multi-tenant catalog schema with trees, money, and soft delete

1 participant