-
Notifications
You must be signed in to change notification settings - Fork 0
The onboarding chain gets a spine: its own model, and a delegation that cannot defeat it #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
188d39d
Schema: OnboardingProposal and its append-only event log
satvikOS a0d2006
The onboarding chain gets a spine: store, delegation-safe actor, expiry
satvikOS 2ad6314
Register the models, pin the counts, resolve ADR-0013
satvikOS 9b0b78f
ADR-0015, the index, and the ledger counts
satvikOS 93ba83d
One implementation of R3, found by a negative control
satvikOS 7a0fe42
Refusing a cross-tenant proposal must not write in the other tenant's…
satvikOS 2860a80
The deferred half is ADR-0009, which already owns it
satvikOS d50c810
Say which cohort figures this repository can check, and which it cannot
satvikOS 8636dcb
Say which of the grain figures this repository can actually check
satvikOS a570d91
Re-measure the grain figures from the workbook the repo actually tracks
satvikOS 673ca26
Say why there is no domain check, so nobody adds one
satvikOS fe1839b
Adversarial suite against a real database, and the three refusals it …
satvikOS 30aaaab
The refusal audit, the address, the enumeration and the brand
claude 1749935
Tests for each of them, and the control that missed the realistic leak
claude 5cd78ac
A compile-time control for the mint
claude 00a5158
Keep the roster out of the fixtures, and the tenant out of a new file
claude b07d03c
An outsider learns nothing from which refusal comes back
claude 22940ae
Merge origin/main into the onboarding proposal chain
claude ba5e488
Merge remote-tracking branch 'origin/main' into pr116-merge-agent
claude 499a614
Merge remote-tracking branch 'origin/main' into HEAD
claude 7076da6
Merge branch 'main' into feat/onboarding-proposal-chain
satvikOS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
apps/web/prisma/migrations/20260821090000_ose_initiated_onboarding_proposals/migration.sql
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| -- CreateEnum | ||
| CREATE TYPE "OnboardingProposalStatus" AS ENUM ('DRAFT', 'PENDING_DIRECTOR', 'APPROVED', 'REJECTED', 'WITHDRAWN', 'EXPIRED'); | ||
|
|
||
| -- CreateEnum | ||
| CREATE TYPE "OnboardingSubjectKind" AS ENUM ('MEMBER', 'ADVISOR', 'OTHER'); | ||
|
|
||
| -- CreateEnum | ||
| CREATE TYPE "OnboardingEventKind" AS ENUM ('CREATED', 'SUBMITTED', 'APPROVED', 'REJECTED', 'WITHDRAWN', 'EXPIRED'); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE "OnboardingProposal" ( | ||
| "id" TEXT NOT NULL, | ||
| "institutionId" TEXT NOT NULL, | ||
| "subjectName" TEXT NOT NULL, | ||
| "subjectEmail" TEXT NOT NULL, | ||
| "subjectEmailNormalized" TEXT NOT NULL, | ||
| "subjectKind" "OnboardingSubjectKind" NOT NULL, | ||
| "subjectKindOther" TEXT, | ||
| "cohort" TEXT NOT NULL, | ||
| "organizationId" TEXT, | ||
| "submittedById" TEXT NOT NULL, | ||
| "status" "OnboardingProposalStatus" NOT NULL DEFAULT 'DRAFT', | ||
| "expiresAt" TIMESTAMP(3) NOT NULL, | ||
| "submittedAt" TIMESTAMP(3), | ||
| "decidedAt" TIMESTAMP(3), | ||
| "decidedById" TEXT, | ||
| "decisionReason" TEXT, | ||
| "openSubjectKey" TEXT, | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
|
||
| CONSTRAINT "OnboardingProposal_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE "OnboardingProposalEvent" ( | ||
| "id" TEXT NOT NULL, | ||
| "proposalId" TEXT NOT NULL, | ||
| "institutionId" TEXT NOT NULL, | ||
| "kind" "OnboardingEventKind" NOT NULL, | ||
| "fromStatus" "OnboardingProposalStatus" NOT NULL, | ||
| "toStatus" "OnboardingProposalStatus" NOT NULL, | ||
| "actorId" TEXT, | ||
| "actorRole" TEXT, | ||
| "onBehalfOfId" TEXT, | ||
| "reason" TEXT, | ||
| "occurredAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
|
||
| CONSTRAINT "OnboardingProposalEvent_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "OnboardingProposal_institutionId_status_idx" ON "OnboardingProposal"("institutionId", "status"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "OnboardingProposal_institutionId_expiresAt_idx" ON "OnboardingProposal"("institutionId", "expiresAt"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "OnboardingProposal_submittedById_idx" ON "OnboardingProposal"("submittedById"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX "OnboardingProposal_id_institutionId_key" ON "OnboardingProposal"("id", "institutionId"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX "OnboardingProposal_institutionId_openSubjectKey_key" ON "OnboardingProposal"("institutionId", "openSubjectKey"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "OnboardingProposalEvent_proposalId_occurredAt_idx" ON "OnboardingProposalEvent"("proposalId", "occurredAt"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE INDEX "OnboardingProposalEvent_institutionId_occurredAt_idx" ON "OnboardingProposalEvent"("institutionId", "occurredAt"); | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "OnboardingProposal" ADD CONSTRAINT "OnboardingProposal_institutionId_fkey" FOREIGN KEY ("institutionId") REFERENCES "Institution"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "OnboardingProposal" ADD CONSTRAINT "OnboardingProposal_organizationId_institutionId_fkey" FOREIGN KEY ("organizationId", "institutionId") REFERENCES "Organization"("id", "institutionId") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "OnboardingProposal" ADD CONSTRAINT "OnboardingProposal_submittedById_fkey" FOREIGN KEY ("submittedById") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "OnboardingProposal" ADD CONSTRAINT "OnboardingProposal_decidedById_fkey" FOREIGN KEY ("decidedById") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "OnboardingProposalEvent" ADD CONSTRAINT "OnboardingProposalEvent_proposalId_institutionId_fkey" FOREIGN KEY ("proposalId", "institutionId") REFERENCES "OnboardingProposal"("id", "institutionId") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "OnboardingProposalEvent" ADD CONSTRAINT "OnboardingProposalEvent_actorId_fkey" FOREIGN KEY ("actorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "OnboardingProposalEvent" ADD CONSTRAINT "OnboardingProposalEvent_onBehalfOfId_fkey" FOREIGN KEY ("onBehalfOfId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
|
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: Tenurework/Tenure
Length of output: 1922
🏁 Script executed:
Repository: Tenurework/Tenure
Length of output: 50373
🌐 Web query:
PostgreSQL documentation foreign key ON DELETE RESTRICT NO ACTION immediate end of statement cascading delete order💡 Result:
In PostgreSQL, NO ACTION and RESTRICT both serve to prevent the deletion or update of a referenced row if a foreign key constraint would be violated [1][2]. However, they differ significantly in their interaction with deferred constraint checking [1][3]. NO ACTION is the default referential action [1][2]. It checks the constraint at the end of the current statement unless the constraint is marked as DEFERRABLE and set to DEFERRED, in which case the check is postponed until the end of the transaction [2][3][4]. Because it supports deferral, NO ACTION allows for complex operations where a temporary violation can be resolved by other commands (such as inserting or deleting rows) before the transaction is committed [1][5]. RESTRICT is a stricter action that does not allow the constraint check to be deferred [1][6]. It prevents the deletion of a referenced row immediately, regardless of whether the constraint is defined as DEFERRABLE or whether you attempt to use SET CONSTRAINTS to defer it [1][2]. Regarding the order of operations, PostgreSQL performs referential actions (like CASCADE) as part of the data-modifying command itself [2]. When multiple foreign key constraints are involved, PostgreSQL does not automatically perform a topological sort to sequence deletes in a specific order to satisfy restrictive constraints [7]. If an operation violates a constraint—whether because of the order of deletions or the presence of RESTRICT/NO ACTION—an error is raised [2][7]. Consequently, if your schema requires a specific deletion order to avoid conflicts with RESTRICT or NO ACTION, you must manage that sequence explicitly within your SQL statements or transaction logic [1][7].
Citations:
Change
onDelete: RestricttoonDelete: NoActionfor the composite organization relation.tenant-cleanup.mjsdeletesInstitutiondirectly. Institution deletion cascades toOrganizationandOnboardingProposal, butRESTRICTcan abort the statement when a proposal still references an organization.NO ACTIONchecks at statement end and still prevents standalone organization deletion that would orphan a proposal.🤖 Prompt for AI Agents