feat(server): org-aware bootstrap + NOT NULL backstop (PR3/4)#71
Merged
Conversation
Every project and admin must belong to an organization. Make the bootstrap CLIs provision one and close the gap at the DB level. - New lib/organizations.ts findOrCreateOrgByName: idempotent on name, used by both CLIs to attach the first admin/project to a tenant (a fresh self-host install has no org until bootstrap; hosted operators pass a per-customer name). - create-admin / create-project take an optional [orgName] (default 'Default') and set organization_id on insert. - Migration 014 enforces organization_id NOT NULL on admin_users and projects, first bucketing any stragglers (rows an older image may have created between the 013 and the org-aware-writer deploys) into a Default org. - Remaining data-only integration test helpers (events, queries, resolution, assess, retention) create and assign an org via the shared test-support helper. 135 server tests pass; type-check + lint clean. Smoke-tested both CLIs: create-project then create-admin with the same org name share one tenant.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
PR3 of 4 for the organizations tenant layer. PRs 1–2 added the
organizationsentity and enforced org-scoped admin RBAC, butorganization_idwas still nullable and the bootstrap CLIs (create-admin/create-project) inserted tenant-less rows. This PR makes every writer org-aware and closes the gap at the DB level, so a tenant-less project or admin can never exist.What
lib/organizations.tsfindOrCreateOrgByName: idempotent on name; both CLIs use it to attach the first admin/project to a tenant. A fresh self-host install has no org until bootstrap; a hosted operator passes a per-customer name to add a second tenant.create-admin/create-project: take an optional[orgName](defaultDefault) and setorganization_idon insert.organization_id NOT NULLonadmin_usersandprojects, first bucketing any stragglers (rows an older image could have created between the 013 deploy and the org-aware-writer deploy) into aDefaultorg so the constraint applies cleanly.test-support/orghelper.Verification
type-check+lintclean.create-project "Smoke Proj" "Acme Corp"thencreate-admin … "Acme Corp"share one tenant (find-or-create reused the org).Follow-up
PR4: docs — ADR-0005 (tenancy model), ROADMAP, OpenAPI note, CHANGELOG.