Skip to content

Conversation

@WeberG619
Copy link

Closes #1596

Problem

Historical dividend records have NULL for investment_amount_cents, causing "N/A" to appear in the "Investment amount" column on /equity/dividends and /equity/dividend_rounds/round/:id pages.

The column was added as nullable in PR #796, but existing dividend records were never backfilled.

Solution

1. One-time backfill script (Onetime::BackfillDividendInvestmentAmounts)

Follows the existing Onetime:: service pattern (like PopulateCompanyInvestorEntities). Run via Rails console before deploying the migration:

Onetime::BackfillDividendInvestmentAmounts.new.perform

Backfill strategy:

  • Share-based dividends (number_of_shares IS NOT NULL): Uses company_investor.investment_amount_in_cents
  • SAFE/convertible dividends (number_of_shares IS NULL): Uses SUM(convertible_securities.principal_value_in_cents) for that investor
  • Fallback: Sets remaining NULL values to 0

2. Migration to enforce NOT NULL

After backfill, adds NOT NULL constraint to dividends.investment_amount_cents. Includes a safety net that sets any remaining NULL values to 0 before applying the constraint.

3. Model validation

Adds validates :investment_amount_cents, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 } to the Dividend model, matching the pattern used on CompanyInvestorEntity.

4. Frontend cleanup

  • Removes "N/A" fallback on /equity/dividends page
  • Removes conditional hasInvestmentAmounts check on /equity/dividend_rounds/round/:id — the "Investment amount" column is now always shown
  • Updates Drizzle schema to mark investmentAmountCents as .notNull()

Deployment steps

  1. Deploy the backfill script
  2. Run Onetime::BackfillDividendInvestmentAmounts.new.perform in production console
  3. Deploy the migration (rails db:migrate)

AI Disclosure

I have used Claude Code (Opus 4.6) to investigate the codebase and implement the fix.

WeberG619 and others added 7 commits February 9, 2026 20:38
Historical dividends have NULL investment_amount_cents, causing "N/A"
on the /equity/dividends page. This adds:

- One-time backfill script (Onetime::BackfillDividendInvestmentAmounts)
  that populates from company_investor.investment_amount_in_cents for
  share-based dividends and convertible_securities.principal_value_in_cents
  for SAFE-based dividends
- Migration to enforce NOT NULL after backfill
- Model validation for investment_amount_cents
- Frontend cleanup: removes N/A fallback and conditional column rendering

Closes antiwork#1596

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The factory calculates total_amount_in_cents from number_of_shares,
which fails when number_of_shares is nil (SAFE dividends).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CreateInvestorsAndDividends was creating dividends without
investment_amount_cents, which now fails validation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Backfill spec: temporarily drop NOT NULL constraint before tests
  (simulates pre-migration state), restore it in after block
- Seed template: add investment_amount_cents to dividend_attributes
  in gumroad.json

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…s in backfill spec

The factory default `investment_amount_cents { number_of_shares * 1000 }` raises
NoMethodError when number_of_shares is nil. Pass investment_amount_cents: 0 explicitly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@WeberG619 WeberG619 closed this Feb 10, 2026
@WeberG619 WeberG619 reopened this Feb 10, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@WeberG619
Copy link
Author

CI isn't triggering for the latest push. Could a maintainer please approve the workflow run? The latest commit fixes the remaining 3 test failures (factory default for investment_amount_cents was trying to compute nil * 1000 when number_of_shares is nil for SAFE-based dividends).

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.

Dividends show N/A for "Investment amount"

1 participant