Repository navigation
feat(securities): express vesting & cliff in months instead of years - #562
maxgubitosi wants to merge 1 commit into
Conversation
Vesting and cliff durations for shares and stock options were entered and stored in years; switch the unit to months (e.g. a 4-year / 1-year-cliff grant is now 48 months / 12 months). - Rename the Share/Option `vestingYears`/`cliffYears` fields to `vestingMonths`/`cliffMonths`, with a Prisma migration that renames the columns and converts existing values from years to months (x12). - Update the Zod mutation schemas, the public OpenAPI schema, the add/get procedures for shares and options, and the share/option creation forms (the numeric input suffix now reads "month(s)"). - No vesting math exists in the app, so this is purely a unit/label/storage change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Thank you for following the naming conventions for pull request titles! 🙏 |
📝 WalkthroughWalkthroughVesting and cliff duration fields are renamed from year-based ( ChangesVesting/Cliff Duration: Years → Months
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
prisma/migrations/20260619131445_vesting_cliff_in_months/migration.sql (1)
10-20: ⚡ Quick winVerify the rename and conversion run atomically.
If the migration runner does not wrap this file in one transaction, a failure after the renames but before both
UPDATEs can leave month-named columns containing year-based values. Please verify the runner behavior or add an explicit transaction around these statements.Atomic migration shape
+BEGIN; + -- AlterTable ALTER TABLE "Share" RENAME COLUMN "vestingYears" TO "vestingMonths"; ALTER TABLE "Share" RENAME COLUMN "cliffYears" TO "cliffMonths"; @@ -- Convert existing durations from years to months UPDATE "Share" SET "vestingMonths" = "vestingMonths" * 12, "cliffMonths" = "cliffMonths" * 12; UPDATE "Option" SET "vestingMonths" = "vestingMonths" * 12, "cliffMonths" = "cliffMonths" * 12; + +COMMIT;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@prisma/migrations/20260619131445_vesting_cliff_in_months/migration.sql` around lines 10 - 20, The migration contains column renames followed by value conversions that could leave the database in an inconsistent state if execution fails between the ALTER TABLE and UPDATE statements. Wrap all the ALTER TABLE statements (for both "Share" and "Option" tables renaming "vestingYears" to "vestingMonths" and "cliffYears" to "cliffMonths") and the subsequent UPDATE statements (that multiply the values by 12 for both tables) within an explicit BEGIN TRANSACTION and COMMIT block to ensure all operations execute atomically, so that either all changes succeed or all roll back together.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@prisma/schema.prisma`:
- Around line 693-694: The comment for cliffMonths incorrectly conflates "no
cliff" with "immediate vesting". Update the cliffMonths comment to clarify that
a value of 0 means "no cliff" (not immediate vesting), while keeping the
vestingMonths comment unchanged since it correctly states that 0 means immediate
vesting. Apply the same comment fix to the duplicate cliffMonths and
vestingMonths fields that appear later in the schema around lines 745-746.
In `@src/server/api/schema/shares.ts`:
- Around line 60-66: Update the schema validation for the month fields in
ShareSchema to enforce both integer and non-negative constraints. For both
cliffMonths and vestingMonths fields, change z.number() to
z.number().int().min(0) to match the Prisma model's Int type definition and
align with the internal tRPC/UI validation that already enforces these
constraints. This ensures the public API schema is consistent with the storage
layer and prevents invalid negative or fractional month values from being
accepted.
---
Nitpick comments:
In `@prisma/migrations/20260619131445_vesting_cliff_in_months/migration.sql`:
- Around line 10-20: The migration contains column renames followed by value
conversions that could leave the database in an inconsistent state if execution
fails between the ALTER TABLE and UPDATE statements. Wrap all the ALTER TABLE
statements (for both "Share" and "Option" tables renaming "vestingYears" to
"vestingMonths" and "cliffYears" to "cliffMonths") and the subsequent UPDATE
statements (that multiply the values by 12 for both tables) within an explicit
BEGIN TRANSACTION and COMMIT block to ensure all operations execute atomically,
so that either all changes succeed or all roll back together.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7a1debd1-503d-44a4-81b2-a12279e33dc5
📒 Files selected for processing (10)
prisma/migrations/20260619131445_vesting_cliff_in_months/migration.sqlprisma/schema.prismasrc/components/securities/options/steps/vesting-details.tsxsrc/components/securities/shares/steps/general-details.tsxsrc/server/api/schema/shares.tssrc/trpc/routers/securities-router/procedures/add-option.tssrc/trpc/routers/securities-router/procedures/add-share.tssrc/trpc/routers/securities-router/procedures/get-options.tssrc/trpc/routers/securities-router/procedures/get-shares.tssrc/trpc/routers/securities-router/schema.ts
| cliffMonths Int @default(0) // vesting cliff in months; 0 means immediate vesting | ||
| vestingMonths Int @default(0) // total vesting period in months; 0 means immediate vesting |
There was a problem hiding this comment.
Clarify the zero-cliff semantics.
cliffMonths = 0 means “no cliff”, not necessarily immediate vesting when vestingMonths is still positive. Keep “immediate vesting” on vestingMonths = 0 only.
Proposed wording fix
- cliffMonths Int `@default`(0) // vesting cliff in months; 0 means immediate vesting
+ cliffMonths Int `@default`(0) // vesting cliff in months; 0 means no cliff
vestingMonths Int `@default`(0) // total vesting period in months; 0 means immediate vesting- cliffMonths Int `@default`(0) // vesting cliff in months; 0 means immediate vesting
+ cliffMonths Int `@default`(0) // vesting cliff in months; 0 means no cliff
vestingMonths Int `@default`(0) // total vesting period in months; 0 means immediate vestingAlso applies to: 745-746
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@prisma/schema.prisma` around lines 693 - 694, The comment for cliffMonths
incorrectly conflates "no cliff" with "immediate vesting". Update the
cliffMonths comment to clarify that a value of 0 means "no cliff" (not immediate
vesting), while keeping the vestingMonths comment unchanged since it correctly
states that 0 means immediate vesting. Apply the same comment fix to the
duplicate cliffMonths and vestingMonths fields that appear later in the schema
around lines 745-746.
| cliffMonths: z.number().openapi({ | ||
| description: "Vesting cliff in months", | ||
| example: 12, | ||
| }), | ||
| vestingYears: z.number().openapi({ | ||
| description: "Vesting Years", | ||
| example: 4, | ||
| vestingMonths: z.number().openapi({ | ||
| description: "Total vesting period in months", | ||
| example: 48, |
There was a problem hiding this comment.
Add integer and non-negative constraints to month fields in public API schema.
The ShareSchema uses z.number() for cliffMonths and vestingMonths, which accepts negative and fractional values. However, the Prisma model defines both as Int type, and internal tRPC/UI validation already enforces .min(0). Update the public API schema to match the storage and internal validation layer.
Proposed validation fix
- cliffMonths: z.number().openapi({
+ cliffMonths: z.number().int().min(0).openapi({
description: "Vesting cliff in months",
example: 12,
}),
- vestingMonths: z.number().openapi({
+ vestingMonths: z.number().int().min(0).openapi({
description: "Total vesting period in months",
example: 48,🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/server/api/schema/shares.ts` around lines 60 - 66, Update the schema
validation for the month fields in ShareSchema to enforce both integer and
non-negative constraints. For both cliffMonths and vestingMonths fields, change
z.number() to z.number().int().min(0) to match the Prisma model's Int type
definition and align with the internal tRPC/UI validation that already enforces
these constraints. This ensures the public API schema is consistent with the
storage layer and prevents invalid negative or fractional month values from
being accepted.
…einc#562) (#2) * feat(securities): express vesting & cliff in months instead of years Vesting and cliff durations for shares and stock options were entered and stored in years; switch the unit to months (e.g. a 4-year / 1-year-cliff grant is now 48 months / 12 months). - Rename the Share/Option `vestingYears`/`cliffYears` fields to `vestingMonths`/`cliffMonths`, with a Prisma migration that renames the columns and converts existing values from years to months (x12). - Update the Zod mutation schemas, the public OpenAPI schema, the add/get procedures for shares and options, and the share/option creation forms (the numeric input suffix now reads "month(s)"). - No vesting math exists in the app, so this is purely a unit/label/storage change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(securities): validate vesting/cliff months as non-negative integers Address upstream review feedback on captableinc#562: - Public API ShareSchema, tRPC and form schemas now require whole, non-negative months, matching the Int columns. - Clarify that cliffMonths = 0 means no cliff (not immediate vesting). - Add unit tests for the months validation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: resolve tsconfig path aliases in vitest Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(securities): format vesting months schema tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * style(prisma): align Option fields after vesting rename Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Máximo Gubitosi <mgubitosi@udesa.edu.ar> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: gabriel <gabriel@Mac-mini-gabriel.local>
…k deleting stakeholders with securities (upstream captableinc#561) (#11) * feat(securities): express vesting & cliff in months instead of years Vesting and cliff durations for shares and stock options were entered and stored in years; switch the unit to months (e.g. a 4-year / 1-year-cliff grant is now 48 months / 12 months). - Rename the Share/Option `vestingYears`/`cliffYears` fields to `vestingMonths`/`cliffMonths`, with a Prisma migration that renames the columns and converts existing values from years to months (x12). - Update the Zod mutation schemas, the public OpenAPI schema, the add/get procedures for shares and options, and the share/option creation forms (the numeric input suffix now reads "month(s)"). - No vesting math exists in the app, so this is purely a unit/label/storage change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(securities): validate vesting/cliff months as non-negative integers Address upstream review feedback on captableinc#562: - Public API ShareSchema, tRPC and form schemas now require whole, non-negative months, matching the Int columns. - Clarify that cliffMonths = 0 means no cliff (not immediate vesting). - Add unit tests for the months validation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: wire Overview dashboard to real cap-table data Replace hardcoded demo numbers on the company Overview with values computed server-side from the same tables the dedicated pages list: share issuances, option grants (excluding cancelled/expired), equity plan pools, SAFEs and convertible notes. - src/server/overview.ts: getOverviewData() computes amount raised, fully-diluted shares, stakeholder count, ownership by stakeholder and by share class, and the per-class summary on a fully-diluted basis (issued + granted options + unallocated pool) - donut-card/summary-table now take data as props - show EmptyOverview when no equity is issued, reserved or raised - empty.tsx: fix 'undefined' rendering in welcome title Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat: implement Cap table and Reports pages Both pages were 'Work in progress' stubs. They are now driven by a shared cap-table engine so they can never disagree with the Overview. - src/server/captable.ts: getCapTable() computes a per-stakeholder x per-share-class fully-diluted matrix (shares, options, equity plan pool, itemized SAFEs/notes, totals) with the same semantics the Overview already shipped with - src/server/overview.ts: getOverviewData() now derives from getCapTable; output verified byte-identical against baselines - Cap table page: summary cards, ownership matrix with per-class columns and totals, equity-plan pool row, convertibles card, empty state; gated behind stakeholder:read like sibling pages - Reports page: four downloadable reports (cap table summary PDF, cap table matrix CSV, securities ledger CSV, stakeholders CSV) generated on demand by /api/reports/[type] with session + RBAC checks; PDF uses the existing @react-pdf/renderer pattern, CSVs use papaparse; no new dependencies Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(securities): enable updating shares and removing investors On the cap table, shares could not be edited and investors (stakeholders) could not be removed: - The "Update Share" row action was a dead label with no handler, and there was no updateShares procedure (addShares is create-only). - The investor table had no delete action and there was no deleteStakeholder procedure. Changes: - Add securities.updateShares procedure + ZodUpdateShareMutationSchema. - Make the share wizard reusable for editing: AddShareFormProvider accepts defaultValues, each step prefills from them, and the final step branches to updateShares (and no longer forces a new document upload) in edit mode. The share row action now opens this pre-filled wizard. - Add stakeholder.deleteStakeholder procedure + a Delete action in the investor table. The procedure refuses to remove an investor who still holds securities (shares/options/SAFEs/notes/investments) since relationMode= "prisma" provides no DB cascade, and it cleans up data-room / update recipient links. - get-shares now selects stakeholderId/shareClassId (needed to prefill edit). - Fix the share-delete toast that incorrectly said "stakeholder". Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(securities): use month-based vesting fields in share editing Adapt the share update procedure and edit form (from captableinc#561) to the cliffMonths/vestingMonths rename (captableinc#562). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: resolve tsconfig path aliases in vitest Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: address upstream review feedback on cap table, reports and stakeholders Fixes for CodeRabbit findings on captableinc#561: - Stakeholder deletion: require the `stakeholder:delete` permission, resolve the stakeholder within the caller's company before touching any rows (prevents cross-tenant deletes of data room / update recipients), and BLOCK deletion with an explicit message listing what is still held when the stakeholder has any share, option, SAFE, convertible note or investment. Runs in a serializable transaction so a concurrent issuance cannot race the check (cascades are emulated by Prisma Client). - Share update: verify the stakeholder and share class belong to the same company; audit with the membership company id. - Reports: escape spreadsheet formula prefixes in every CSV header/cell. - Overview: gate behind `stakeholder:read` like the cap table page. - Stakeholder table: move hooks into a StakeholderActionsCell component, refresh only on success, disable Delete while pending. - Share stepper: keep the modal open until the mutation succeeds. - Cap table PDF: correct matrix column count; use a built-in font instead of fetching one over the network. - Use `Button asChild` for link CTAs; constrain report card type; reject empty ids in update/delete payloads. - Add unit tests for CSV sanitisation and the stakeholder deletion guard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(securities): format vesting months schema tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: resolve biome and type errors in stakeholder table and tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * style(prisma): align Option fields after vesting rename Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * style: apply biome formatting to cap table, reports and stakeholder changes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Máximo Gubitosi <mgubitosi@udesa.edu.ar> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: gabriel <gabriel@Mac-mini-gabriel.local>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(e2e): add Playwright harness with fictional scenario seed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(e2e): store rates and group ownership as fractions Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * build(e2e): add @playwright/test and resolve seed import for ESM Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(e2e): assert overview stats and run seed unit tests in vitest Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(e2e): express seeded vesting in months after captableinc#562 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(e2e): seed scenarios through the cap table contract Write Decimal money with currency, CompanySettings, the group link, a closed FundingRound and POSTED ledger ISSUANCE rows for every seeded security, so engine projections match the registers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(e2e): refuse to seed non-disposable databases The seed creates admin users with a public password, and NODE_ENV alone does not protect shared databases (Prisma loads .env; pnpm e2e and tsx leave NODE_ENV unset). Seeding now requires a local host, a database named for e2e/test, or an explicit E2E_ALLOW_SEED=1 (set in the CI e2e job); NODE_ENV=production always refuses. Also: scope the README reset command to an explicit E2E DATABASE_URL, give the CI build 6 GB of heap, and assert the parent's 10,000,000 authorized shares. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: gabriel <gabriel@Mac-mini-gabriel.local> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Vesting and cliff durations for shares and stock options were previously entered and stored in years. This PR switches the unit to months (e.g. a 4-year grant with a 1-year cliff is now 48 months / 12 months), which is the granularity most grants actually use.
Changes
Share.{vestingYears,cliffYears}andOption.{vestingYears,cliffYears}to{vestingMonths,cliffMonths}.20260619131445_vesting_cliff_in_months) — renames the columns and converts existing values from years to months (* 12), so existing rows keep the same real-world duration.Notes
cliffYears/vestingYearsfields are renamed tocliffMonths/vestingMonths(src/server/api/schema/shares.ts).Testing
prisma generateregenerates cleanly with the renamed fields.pnpm build(Next.js production build) passes with no type errors.Summary by CodeRabbit