feat(db): add workspace-scoped department foundation - #86
Open
Umoren wants to merge 2 commits into
Open
Conversation
|
Caution Review failedAn error occurred during the review process. Please try again later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Summary
Part of #42.
This PR adds the database foundation for departments inside one Garden workspace. It adds department records, department membership, four department roles, workspace-isolation constraints, shared validation schemas, and verification tests.
The main system effect is that future department APIs can rely on PostgreSQL to reject cross-workspace membership and duplicate membership. This PR does not add those APIs or any user interface.
Scope
departmentanddepartment_membertables.viewer,member,lead, andadmindepartment roles.Invariants
Design
Garden stores workspaces in the
organizationtable. Each department belongs to one workspace. A department member points to an existing Better Auth workspace member.erDiagram ORGANIZATION_WORKSPACE ||--o{ DEPARTMENT : contains ORGANIZATION_WORKSPACE ||--o{ MEMBER : contains DEPARTMENT ||--o{ DEPARTMENT_MEMBER : has MEMBER ||--o{ DEPARTMENT_MEMBER : joinsdepartment_memberstoresworkspace_idwith both relationship identifiers. Two composite foreign keys then enforce the tenant boundary:This design makes PostgreSQL the source of truth for workspace isolation. A caller cannot add a member from workspace B to a department in workspace A, even if application code misses that check.
The validation layer uses
drizzle-zodso request shapes stay aligned with the Drizzle schema. Department updates accept onlynameandslug. They cannot changeidor move a department to another workspace. Membership updates accept only a supported role.The migration was generated from the Drizzle schema. The generated statements were reordered so PostgreSQL creates the composite unique indexes before the foreign keys that reference them.
Duplicate and idempotency review
(workspace_id, slug)(workspace_id, department_id, member_id)Privacy and security review
Data, migration, and rollback
departmentanddepartment_member, their constraints and indexes, plus one composite unique index onmember.drizzle-kit checkpassed.Verification
Commands and actual results:
The first full test run started three PostgreSQL containers in parallel. All three timed out while waiting for their readiness log. No test assertion failed. The focused department suite passed, and the full suite then passed with
--maxWorkers=1.Operations
0045_department_foundationthrough the normal database migration process.Agent declaration
AGENTS.mdinstructions.