Skip to content

Migration Plan Mongo to Auth Core

This document is FINAL and ENFORCEABLE for migrating legacy systems to the new architecture.


This plan defines how to migrate:

  • MongoDB users
  • Finance system companies
  • Legacy permission system

into:

  • Auth Backend (identity, memberships, permissions)
  • Platform Core (companies, entitlements, subscriptions)

No big-bang migration
No downtime
No dual source of truth long-term
Fail-safe and reversible steps

LegacyNew System
users (Mongo)Auth users
company_usersAuth memberships
permissionsAuth permissions
package_permissionsCore entitlements
finance companiesCore companies

  • keep Mongo as source of truth

  • build sync job: Mongo → Auth Mongo → Core

  • validate data consistency


  • new writes go to:

    • Mongo (legacy)
    • Auth/Core (new)
  • ensure both stay aligned


  • backend reads from:

    • Auth (users, permissions)
    • Core (entitlements)
  • Mongo becomes fallback only


  • disable writes to Mongo
  • validate full system using Auth/Core

  • remove Mongo logic
  • remove legacy permission code
  • remove dual write

  • copy users → Auth
  • map:
    • _id → uuid
    • email → email
    • roles → tenantRole

  • move finance companies → Core
  • assign unique UUID
  • map legacy IDs

  • create membership per user-company
  • assign:
    • role
    • modules (initial grants)
    • permissions

  • map legacy permissions → new permission keys
  • normalize naming (e.g. finance.expense.view)

  • run scheduled job (cron)
  • detect changes
  • push to Auth/Core

  • Mongo change streams
  • trigger updates instantly

Before switching reads:

  • user count matches
  • company count matches
  • membership count matches
  • permission parity validated

At any phase:

  • revert reads to Mongo
  • disable Auth/Core reads
  • maintain data sync

  • inconsistent IDs
  • missing permissions
  • stale cache

Mitigation:

  • strict validation
  • logs
  • metrics

Migration is complete only when Mongo is no longer used for:
- users
- permissions
- company access