Skip to content

fix(db): normalize legacy 'general fund' initiative_type to 'general_fund' (DO NOT MERGE)#153

Open
mlehotskylf wants to merge 5 commits into
mainfrom
fix/normalize-initiative-types
Open

fix(db): normalize legacy 'general fund' initiative_type to 'general_fund' (DO NOT MERGE)#153
mlehotskylf wants to merge 5 commits into
mainfrom
fix/normalize-initiative-types

Conversation

@mlehotskylf

@mlehotskylf mlehotskylf commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Audited all initiative types across DynamoDB, the migration script, backend validation, and UI filters. Found several mismatches between what the migration writes to the DB and what the rest of the stack expects. This PR fixes all of them.

Type mismatches fixed

DynamoDB entityType Was written as Now written as How
initiative (= general fund) general fund (space) general_fund Migration normalisation
ostif ostif security_audit Migration normalisation (OSTIF runs security audits)

Legacy types surfaced under General Fund

other (25 rows) and community (3 rows) have no dedicated UI category. Rather than renaming them in the DB, they are surfaced transparently under the General Fund tab:

  • Backend: general_fund filter query uses ANY($1) to also include other and community rows
  • Frontend card: other and community are mapped to the general_fund card config (same label, icon, colours)

Impact without this fix: on go-live, 123 general fund initiatives would be invisible on the General Funds tab and rejected by type validation on updates; 11 OSTIF initiatives would show with default fallback styling.

Screenshot 2026-06-14 at 6 15 41 PM

Changes

  • backend/db/scripts/migrate_dynamo_to_postgres.py — normalise initiativegeneral_fund and ostifsecurity_audit; fix OSTIF detail block to read raw DynamoDB type before normalisation
  • backend/internal/infrastructure/db/initiative_repository.gogeneral_fund filter includes other and community via ANY($1)
  • frontend/app/components/shared/components/initiative-card/initiative-card.config.ts — map other and community to general_fund card config

Test plan

  • DEV rows manually fixed (Testing Crowdfunding project Creation, Test Crowdfunding Project now have initiative_type = 'general_fund')
  • Re-run Python migration script against DEV DynamoDB snapshot: verify no general fund or ostif rows produced
  • Verify General Funds tab on DEV shows general fund, other, and community initiatives
  • Verify OSTIF initiatives appear under Security Audits tab

🤖 Generated with Claude Code

…fund'

Two rows migrated from DynamoDB in 2022 have initiative_type = 'general fund'
(space) instead of the canonical 'general_fund' (underscore) used by all new
code. This causes them to be invisible on the General Funds filter tab and
rejected by ValidInitiativeTypes on any update attempt.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Michal Lehotsky <mlehotsky@linuxfoundation.org>
Copilot AI review requested due to automatic review settings June 14, 2026 23:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Normalizes legacy Postgres data migrated from DynamoDB where initiative_type was stored as the display string 'general fund' instead of the canonical code value 'general_fund', restoring correct backend validation and frontend filtering behavior for General Funds.

Changes:

  • Add a SQL migration that updates any initiatives.initiative_type = 'general fund' rows to 'general_fund'.
  • Update updated_on for the affected rows as part of the same statement.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

mlehotskylf and others added 2 commits June 14, 2026 16:40
The Python migration script restored DynamoDB's entityType quirk as
'general fund' (space) instead of the canonical 'general_fund' (underscore)
used by ValidInitiativeTypes and all frontend code. Fix it at the source so
production migration never produces the wrong value.

The SQL migration (002) is kept to fix environments that ran the old script
(e.g. DEV already has 2 affected rows).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Michal Lehotsky <mlehotsky@linuxfoundation.org>
…cient

The SQL migration was added to fix DEV rows written by the old script, but:
- On prod the fixed Python script runs before the app deploys, so 002 is a no-op
- SQL migrations run forever on every new environment — wrong mechanism for a
  one-time dev cleanup
- DEV can be fixed with a manual UPDATE or by re-running the fixed script

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Michal Lehotsky <mlehotsky@linuxfoundation.org>
Copilot AI review requested due to automatic review settings June 14, 2026 23:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread backend/db/scripts/migrate_dynamo_to_postgres.py
mlehotskylf and others added 2 commits June 14, 2026 18:15
OSTIF initiatives are security audits run by the Open Source Technology
Improvement Fund. Reclassify them to security_audit so they match
ValidInitiativeTypes and appear correctly in the UI filter.

The OSTIF-specific detail block still reads the raw DynamoDB entityType
(before normalisation) to correctly populate initiative_ostif_detail.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Michal Lehotsky <mlehotsky@linuxfoundation.org>
Legacy initiative types 'other' and 'community' have no dedicated UI
representation. Rather than renaming them in the DB, surface them under
the General Fund tab:

- Backend: when filtering by general_fund, query also includes 'other'
  and 'community' rows via ANY($1)
- Frontend card: map 'other' and 'community' to the general_fund card
  config (label, icon, colours)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Michal Lehotsky <mlehotsky@linuxfoundation.org>
Copilot AI review requested due to automatic review settings June 15, 2026 01:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread backend/internal/infrastructure/db/initiative_repository.go
@mlehotskylf mlehotskylf changed the title fix(db): normalize legacy 'general fund' initiative_type to 'general_fund' fix(db): normalize legacy 'general fund' initiative_type to 'general_fund' (DO NOT MERGE) Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants