Skip to content

feat: data migration from mongo/fs to the PostgreSQL sink - #1582

Merged
dcoric merged 29 commits into
finos:feat/postgresfrom
dcoric:feat/postgres-data-migration
Aug 28, 2026
Merged

feat: data migration from mongo/fs to the PostgreSQL sink#1582
dcoric merged 29 commits into
finos:feat/postgresfrom
dcoric:feat/postgres-data-migration

Conversation

@dcoric

@dcoric dcoric commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Description

Draft, stacked on #1532 (PostgreSQL sink). The diff below currently includes the #1532 changes. Once #1532 merges, this branch will be rebased onto main so only the migration changes remain, and the draft flag will be removed.

Adds a data-migration utility to copy users, repos and pushes from a mongo or fs (NeDB) backend into PostgreSQL.

  • src/db/postgres/migrate.ts orchestrates the import. It is idempotent: users and repos that already exist (matched by username/email and URL) are skipped, and pushes are upserted by id, so the import is safe to re-run.
  • Source readers migrateMongoSource.ts (MongoDB driver) and migrateFileSource.ts (NeDB) read from the legacy backend with their own connection while the importer writes through the active PostgreSQL sink, so the two connections never clash.
  • Record _ids are not carried over; PostgreSQL assigns fresh UUIDs. Push ids (text) are preserved by the upsert.
  • Invoked via npm run migrate:postgres -- --from <mongo|fs> [--mongoUrl ... | --dataDir ...].
  • Unit tests cover the orchestrator and both sources; a gated integration test covers the fs to postgres path end to end.

Note: the integration test exercises the fs to postgres path only, because the PostgreSQL CI lane does not run a Mongo service. The mongo source is unit-tested with a mocked driver. Wiring a Mongo service into that lane for full mongo-to-postgres integration coverage is a reasonable follow-up.

Related Issue

Resolves #1557

Checklist

General

Documentation

  • Documentation has been added/updated for any new features

Configuration

  • If configuration schema (config.schema.json) was modified: (not modified in this PR)

Tests

  • Tests have been added/updated for new functionality
  • Unit tests pass (npm test)
  • Linting and formatting pass (npm run lint and npm run format:check)
  • Type checks pass (npm run check-types)

@netlify

netlify Bot commented Jun 8, 2026

Copy link
Copy Markdown

Deploy Preview for endearing-brigadeiros-63f9d0 ready!

Name Link
🔨 Latest commit 407e003
🔍 Latest deploy log https://app.netlify.com/projects/endearing-brigadeiros-63f9d0/deploys/6a6730da285b33000871eb36
😎 Deploy Preview https://deploy-preview-1582.git-proxy.preview.finos.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.64706% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.64%. Comparing base (864be89) to head (fbb56bb).

Files with missing lines Patch % Lines
src/db/postgres/migrateFileSource.ts 96.66% 0 Missing and 1 partial ⚠️
src/db/postgres/migrateMongoSource.ts 95.45% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##           feat/postgres    #1582      +/-   ##
=================================================
+ Coverage          86.48%   86.64%   +0.15%     
=================================================
  Files                108      111       +3     
  Lines               5986     6071      +85     
  Branches            1111     1124      +13     
=================================================
+ Hits                5177     5260      +83     
  Misses               527      527              
- Partials             282      284       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kriswest

kriswest commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

If you start working these PRs from FINOS repo branches (which you should be able to do as a member of the (trusted) contributors team) then you could target these PRs at the the other PR branch so we only see the diff for the additions... Once the the other PR merges and its branch is deleted github switches the target to main automatically.

If you are using the DB adaptor to perform the migration (only took a brief look so far), can this not be generalised to handle migration to/from any adaptor? That would be preferable to a postgres as destination specific migration tool (I'm not convinced thats the right direction :-p ).

Comment thread scripts/migrate-to-postgres.ts
@fabiovincenzi

Copy link
Copy Markdown
Contributor

Nice!

@jescalada jescalada mentioned this pull request Aug 10, 2026
@dcoric
dcoric changed the base branch from main to feat/postgres August 24, 2026 06:32
@dcoric
dcoric marked this pull request as ready for review August 24, 2026 10:20
@dcoric
dcoric requested a review from a team as a code owner August 24, 2026 10:20

@jescalada jescalada 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.

Thanks for this! Just a few comments on this one - and Fabio's comment to fix up 👍🏼

Comment thread src/db/postgres/migrateMongoSource.ts
Comment thread src/db/postgres/migrateFileSource.ts Outdated
Comment thread test/db/postgres/migrate.test.ts
Comment thread test/db/postgres/migrate.test.ts
dcoric added 5 commits August 27, 2026 09:43
Review feedback on the data migration:

- Pushes now stream through the migration in batches (default 500)
  instead of one toArray() call, so production tables with tens of
  thousands of diff-carrying documents no longer sit in memory whole.
  The mongo source iterates a cursor; the NeDB source chunks its
  in-memory records to the same contract.
- The file source fails fast on a missing data directory or one that
  contains no fs sink datastores, and loads explicitly so a corrupt
  datastore surfaces as an error instead of reading as empty.
- The CLI closes the destination pool after the summary, so the
  process exits instead of hanging on open handles.
- Tests document that passwords are copied verbatim (hashing lives in
  the service wrapper, not the adapter) and that createRepo persists
  the permission map without separate role calls.
…-data-migration

# Conflicts:
#	website/docs/architecture/architecture.md

@jescalada jescalada 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.

LGTM, just needs conficts fixed 🚀

…-data-migration

# Conflicts:
#	website/docs/architecture/architecture.md
@dcoric
dcoric merged commit 83377fe into finos:feat/postgres Aug 28, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostgreSQL sink: data migration from mongo/fs to postgres

4 participants