Migrate an existing Prisme.ai installation from MongoDB to PostgreSQL for the three structured-data stores (users, permissions, collections).
This guide migrates the three Prisme.ai structured-data stores (users, permissions and collections) from MongoDB to PostgreSQL. It applies when you already run Prisme.ai on Mongo and want to move to Postgres (the recommended engine for new deployments).The approach is a data reimport, not a live replication: you stand up a fresh Postgres-backed install, dump the Mongo databases, and load each dump into its Postgres counterpart with a migration script that upserts every document by id.
The schemas come from the platform, not from the migration. The relational schema of all three databases is provisioned the clean way: the backends create the users and permissions tables on startup, and the collections schema is generated by the MongoDB platform runtime and applied as collections.sql. The migration script only loads data into those existing tables and adapts each value to their real column types; it does not design the schema.
Prisme.ai’s three stores run on a single relational engine; you cannot mix Postgres and Mongo across users, permissions and collections. This migration moves all three at once. See Databases / PostgreSQL.
Overview
1
Deploy the Postgres-backed platform
Configure and deploy the core & apps Helm charts against PostgreSQL, and let the backends create their own tables.
2
Import the collections SQL schema
Generate the collections schema from the source runtime and apply it so every collection table exists with the correct types and constraints.
3
Dump the MongoDB databases
mongodump the users, permissions and collections databases.
4
Run the migration script
Load each dump into its Postgres database with mongo_to_postgres.py, once per database.
Prerequisites
A running Postgres-backed Prisme.ai install (see Step 1); the target databases must exist and their connection URLs be known.
collections.sql: the collections schema as SQL DDL, generated from your source (Mongo-backed) runtime (see Generating the collections schema). It carries every collection table with its real types, constraints and defaults.
Run the whole migration against an empty or freshly-initialized Postgres target. The script is idempotent (safe to re-run), but the source of truth here is the Mongo dump; do not point it at a Postgres database that already holds diverging data.
Every service is up & running: prismeai-api-gateway, prismeai-workspaces, prismeai-events, prismeai-runtime, and the apps.
The users and permissions schemas are initialized. The backends create their own tables on first startup:
prismeai-api-gateway auto-creates the users tables (accounts, organizations, memberships, roles, API keys…).
prismeai-workspaces auto-creates the permissions tables (workspace-level RBAC).
Let the backends fully boot so these tables exist. The migration script adapts to the real column types and defaults of the target tables; those must be in place first.
2. Import the collections SQL schema
Unlike users and permissions, the collections tables are not created by a backend on startup; they are provisioned lazily as platform workspaces are imported. To get the schema the clean way without replaying that whole path, generate it from your source runtime and apply it to the target.
Generating the collections schema
The source platform (the runtime still running on MongoDB) exposes an internal endpoint that emits the full collections schema as SQL DDL. Generate collections.sql from a running runtime pod:
$INTERNAL_API_KEY is the runtime’s internal API key, already present in the pod’s environment, which is why the call is made from inside the runtime. The /sys/collections/schema route is internal-only and rejects any request without the matching key. Copy the resulting collections.sql out of the pod to where you will run psql (e.g. kubectl cp <pod>:/path/collections.sql ./collections.sql).
Applying the schema
psql "$COLLECTIONS_PG_URL" -f ./collections.sql
This creates every collection table with the exact types, constraints and defaults the platform expects, so the migration only has to load rows into them.
$COLLECTIONS_PG_URL must include the database name in the URL (e.g. postgres://user:pass@host:5432/collections?sslmode=require). With psql, a separate -d name flag replaces the whole connection string from the URL; put the database in the URL instead. See psql troubleshooting.
3. Dump the MongoDB databases
Dump the three source databases from your existing Mongo cluster into a single directory:
This produces ./mongodump/<db>/<collection>.bson (plus .metadata.json sidecars), exactly the layout the migration script expects.
Add --readPreference=secondary when dumping a production cluster so the dump reads from a replica instead of the primary.
4. Run the migration script
Load each dump into its Postgres database, once per database. Point --mongo-db at the source Mongo database (a sub-directory of the dump) and --pg-database at the target Postgres database:
--pg-database overrides the database name in --pg-dsn, so you can keep a single generic $PG_URL (host / user / password) and only change the target database between runs.
Each run prints, per collection, the primary key used, document count and the number of rows upserted, e.g. -> upserted 1240 row(s). Empty and excluded collections are reported as skipped.
How the script works
Loads into the existing schema
When a table already exists, created by the backends (users, permissions) or by collections.sql, the script reads its real column types, defaults and constraints from information_schema and coerces every Mongo value to match: strings to timestamptz, epoch numbers to dates, objects to jsonb, string arrays to text[], and so on. This is the reliable path, and the reason you should provision collections.sql up front.For a collection whose table is missing, the script falls back to inferring a schema from the data it reads and creating the table itself. Treat this as a last resort: the inferred types are guessed from sample values and can be wrong, causing failures at insertion or at read time (see the warning in Step 2). Provision the real schema for every important table instead of relying on this fallback.
Idempotent: safe to re-run
Rows are UPSERTed on their primary key (INSERT … ON CONFLICT (pk) DO UPDATE), so ids are preserved and re-running never duplicates rows nor errors. If a run is interrupted, just run it again.
Primary key detection
The primary key is _id if present, otherwise id, decided per collection. A non-empty collection with neither is treated as invalid and aborts the run (override with --skip-invalid). Empty collections are skipped.
camelCase → snake_case column names
Mongo field names are converted to snake_case to match the platform ORM (e.g. authData → auth_data, expiresAt → expires_at); _id is kept as-is. Use --column-naming preserve to keep the original Mongo names instead.
NOT NULL defaults
When a NOT NULL column has no value in the Mongo document, the script applies the table’s real Postgres DEFAULT (any type), falling back to [] for arrays and false for booleans, matching the ORM defaults that Mongo documents don’t store.
Excluding rows or whole collections
--exclude skips data at two levels:
collection:field=value: skip matching documents. Some rows are seeded by the API at startup and would collide with the dump on a secondary unique constraint; the defaults skip those platform-workspace rows.
collection (bare name): skip an entire collection, before it is even read. Useful for temp/cache collections you don’t want in Postgres (e.g. --exclude '<workspaceId>/atlasReportsTemp', using the decoded name).
Both forms are repeatable and comma-separated; anything you pass is added to the defaults.
Options reference
Flag
Purpose
--dump-dir
Path to the mongodump output directory.
--mongo-db
Source Mongo database(s): the <dump-dir>/<db> sub-directory to import. Comma-separated.
--pg-dsn
Target Postgres DSN (or PG_DSN env var).
--pg-database
Target Postgres database, overrides the /dbname of --pg-dsn.
--pg-schema
Target Postgres schema (default public).
--collections
Import only these collections (comma-separated).
--exclude
Skip data: collection:field=value skips matching documents, a bare collection skips the whole collection. Repeatable; added to the platform-seed defaults.
--column-naming
snake (default) or preserve.
--skip-invalid
Skip non-empty collections that have no _id/id instead of aborting.
--batch-size
Rows per upsert batch (default 1000).
Verification
After importing all three databases:
Row counts: spot-check a few collections against Mongo:
Log in to the platform as an existing user and confirm organizations, workspaces and permissions resolve correctly.
Open a workspace that uses collections and confirm its data is present.
Table and column identifiers are case-sensitive in Postgres and quoted by the ORM (e.g. "Users", "AccessTokens"). Quote them in psql queries.
Troubleshooting
psql connects to the wrong server
connection to server on socket "/tmp/.s.PGSQL.5432" failed means psql ignored your connection URL and fell back to the local socket. This happens when you pass both a URL and a bare -d dbname; the -d replaces the whole connection string. Put the database in the URL instead:
Also confirm the variable is set (echo "$COLLECTIONS_PG_URL"); an empty value produces the same fallback.
null value in column … violates not-null constraint
A NOT NULL column received no value and has no usable default. The script auto-fills DB defaults, empty arrays and false booleans; anything else means a genuinely missing required field or a type that couldn’t be coerced. The script prints a one-line diagnostic naming the field, column and reason just before the failure; use it to identify the field.
duplicate key value violates unique constraint
A row already exists in Postgres (seeded by the API at startup) that collides with the dump on a secondary unique constraint (not the primary key). Exclude the seeded rows with --exclude. The platform-workspace roles are excluded by default (roles:subjectId=platform).
Aborting: invalid collection(s)
A non-empty collection has neither _id nor id, so no stable key exists to upsert on. Inspect the collection; if it is genuinely disposable, re-run with --skip-invalid.
Order matters. Deploy and let the backends create the users/permissions tables (Step 1) and import the collections schema (Step 2) before running the script (Step 4). The importer adapts to the real column types and defaults of the target tables, so those tables must exist first.
Was this page helpful?
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Prisme.ai","colors":{"primary":"#255BE0","light":"#4480ED","dark":"#255BE0"},"logo":{"light":"https://mintcdn.com/prismeai/_sSeZNUvs7sBNa3K/logo/light.svg?fit=max\u0026auto=format\u0026n=_sSeZNUvs7sBNa3K\u0026q=85\u0026s=4361458c99ac06f7a551020a022b802c","dark":"https://mintcdn.com/prismeai/_sSeZNUvs7sBNa3K/logo/dark.svg?fit=max\u0026auto=format\u0026n=_sSeZNUvs7sBNa3K\u0026q=85\u0026s=3a821be1a9c43dfe88d750b42b0879ca"},"favicon":"https://mintcdn.com/prismeai/_sSeZNUvs7sBNa3K/favicon.svg?fit=max\u0026auto=format\u0026n=_sSeZNUvs7sBNa3K\u0026q=85\u0026s=e62b8218f2529b02ddcca7e240aeb121","api":{"params":{"expanded":"all"},"playground":{"display":"interactive"},"examples":{"defaults":"required","languages":["curl","javascript","python"]}},"background":{"color":{"light":"#F2F3F5","dark":"#0A0A0F"}},"navbar":{"links":[{"href":"mailto:support@prisme.ai","label":"Support"}],"primary":{"type":"button","label":"Ask for a demo","href":"https://www.prisme.ai/request-demo"}},"footer":{"socials":{"github":"https://github.com/prismeai","linkedin":"https://linkedin.com/company/prismeai"}},"seo":{"metatags":{"keywords":"sovereign agentic platform, plateforme agentique souveraine, AI Information System, enterprise AI platform, AI agents, agent governance, traceable AI, cloud agnostic, LLM agnostic, agentic workflows","robots":"index, follow","og:site_name":"Prisme.ai Documentation"},"indexing":"navigable"},"fonts":{"family":"PP Telegraf","weight":400},"contextual":{"options":["download-spec"],"display":"header"},"styling":{"latex":true},"navigation":{"global":{"anchors":[{"anchor":"Blog","icon":"newspaper","href":"https://blog.prisme.ai"},{"anchor":"Legacy Documentation","icon":"clock-rotate-left","href":"https://prismeai-legacy.mintlify.app/"}]},"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"prismeai","hasAudioNarration":false,"actualSubdomain":"prismeai","customDomains":["docs.prisme.ai"],"gitSource":{"type":"gitlab","owner":"prisme.ai","repo":"docs","deployBranch":"main","contentDirectory":"","isPrivate":false,"projectId":88542754,"mountPath":"","label":"","_id":"6aeca605e8540e9445e0c511"},"feedback":{"thumbs":true,"edits":false,"issues":true,"agentFeedback":true},"entitlements":{"AI_CHAT":{"status":"DISABLED"}},"buildId":"6af6da66a071dcdd90fd9ceb","clientVersion":"0.0.4177","searchFilterCounts":[{"language":"default","tag":"API Reference","count":386},{"language":"default","tag":"Platform API","count":180},{"language":"default","tag":"Products","count":115},{"language":"default","tag":"App Store","count":88},{"language":"default","tag":"Agent Creator API","count":82},{"language":"default","tag":"Prisme.ai Workspaces","count":55},{"language":"default","tag":"Organizations","count":50},{"language":"default","tag":"Knowledges API","count":41},{"language":"default","tag":"Connectors","count":37},{"language":"default","tag":"API Gateway","count":37}]},"assistantConfig":{"enableStarterQuestions":false,"deflection":{"enabled":true,"type":"email","email":"support@prisme.ai"}},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[],"googleFontsInlined":false},"customCss":[{"filePath":"custom.css","content":"@font-face{font-family:'PP Telegraf';src:url('https://uploads.prisme.ai/yj7mmn-/ffcs3WSD7NIciPjlrySpO.PPTelegraf-Regular.otf') format('opentype');font-weight:100 600;font-style:normal;font-display:swap}@font-face{font-family:'PP Telegraf';src:url('https://uploads.prisme.ai/yj7mmn-/lpdrPfRwHqg0SiRWe_hec.PPTelegraf-Ultrabold.otf') format('opentype');font-weight:700 900;font-style:normal;font-display:swap}:root{--prisme-primary: #255BE0;--prisme-bg: #F2F3F5;--prisme-fg: #0A0A0F;--prisme-card: #FFFFFF;--prisme-border: #E3E6EC;--prisme-muted: #6B7080;--prisme-secondary: #E3E5EB;--prisme-accent-warm: #F5A623;--prisme-radius: 0.5rem;--prisme-tabs-sticky-top: 4rem}@media (min-width: 1024px){:root{--prisme-tabs-sticky-top: 7rem}}[data-theme=\"dark\"],.dark{--prisme-bg: #0A0A0F;--prisme-fg: #FAFAFA;--prisme-card: #0A0A0F;--prisme-border: #1F2028;--prisme-muted: #9CA0AE;--prisme-secondary: #1F2028}body{font-family:'PP Telegraf', 'Inter', system-ui, -apple-system, sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-rendering:optimizeLegibility}h1,h2,h3,h4{font-weight:500}#navbar{border-bottom:1px solid var(--prisme-border)}#sidebar{border-right:1px solid var(--prisme-border)}callout{border-radius:var(--prisme-radius);border:1px solid var(--prisme-border)}[data-callout-type=\"warning\"] [data-component-part=\"callout-content\"],[data-callout-type=\"warning\"] [data-component-part=\"callout-content\"] strong{color:var(--prisme-fg)!important}code-block{border-radius:var(--prisme-radius)}#footer{border-top:1px solid var(--prisme-border)}[data-component-part=\"tabs-list\"]{position:sticky;top:var(--prisme-tabs-sticky-top);z-index:20;margin-bottom:0;padding-top:0.5rem;background:var(--prisme-bg);border-bottom-width:2px;border-bottom-color:var(--prisme-border);-webkit-backdrop-filter:saturate(180%) blur(6px);backdrop-filter:saturate(180%) blur(6px)}[data-component-part=\"tab-button\"]{color:var(--prisme-muted);font-weight:500;transition:color 0.15s ease, box-shadow 0.15s ease}[data-component-part=\"tab-button\"]:hover{color:var(--prisme-fg)}[data-component-part=\"tab-button\"][data-active=\"true\"]{color:var(--prisme-primary);font-weight:700;box-shadow:inset 0 -3px 0 0 var(--prisme-primary)}[data-component-part=\"tab-content\"]{border:1px solid var(--prisme-border);border-top:none;border-radius:0 0 var(--prisme-radius) var(--prisme-radius);padding:1.25rem 1.5rem;margin-bottom:2rem;background:var(--prisme-card)}[data-theme=\"dark\"] [data-component-part=\"tab-content\"],.dark [data-component-part=\"tab-content\"]{background:rgba(255, 255, 255, 0.02)}"},{"filePath":"tutorials/player.css","content":".pv-host{display:block;width:100%;aspect-ratio:16 / 9;margin:1.5rem 0}.pv.video-js{--pv-primary: #205BE1;--pv-ink: #151B24;--pv-muted: #69707F;--pv-border: #E4E7ED;--pv-surface: #F8FAFD;--pv-page: #FFFFFF;--pv-cover: #1E50D2;--pv-cover-eyebrow: #9DB4EE;--pv-cover-sub: #C9D8F7;--pv-title-font: Arial;--pv-pill-bg: #FFFFFF;--pv-pill-text: var(--pv-primary);container-type:size;background:var(--pv-page);border-radius:14px;overflow:hidden;font-family:-apple-system, BlinkMacSystemFont, \"Segoe UI\", Arial, sans-serif;color:var(--pv-ink)}.pv.video-js.vjs-fullscreen,.pv.video-js.vjs-full-window{border-radius:0}.pv.video-js>*{--u: min(1cqw, calc(100cqh / 56.25));--ox: calc(50cqw - 50 * var(--u));--oy: calc(50cqh - 28.125 * var(--u))}.pv.video-js .vjs-tech{left:calc(var(--ox) + var(--fx) * var(--u));top:calc(var(--oy) + (var(--fy) + 2.4) * var(--u));width:calc(var(--sw) * var(--u));height:calc(var(--sh) * var(--u));object-fit:cover;background:#fff;border-radius:0 0 calc(1 * var(--u)) calc(1 * var(--u))}.pv.video-js .vjs-poster{display:none}.pv.video-js .pv-frame{position:absolute;left:calc(var(--ox) + var(--fx) * var(--u));top:calc(var(--oy) + var(--fy) * var(--u));width:calc(var(--sw) * var(--u));height:calc((var(--sh) + 2.4) * var(--u));border-radius:calc(1 * var(--u));box-shadow:0 calc(1.2 * var(--u)) calc(3 * var(--u)) rgba(21, 27, 36, .18), 0 0 0 1px var(--pv-border);pointer-events:none}.pv.video-js .pv-bar{height:calc(2.4 * var(--u));display:flex;align-items:center;gap:calc(.55 * var(--u));padding:0 calc(1 * var(--u));background:var(--pv-surface);border-bottom:1px solid var(--pv-border);border-radius:calc(1 * var(--u)) calc(1 * var(--u)) 0 0}.pv.video-js .pv-bar i{width:calc(.7 * var(--u));height:calc(.7 * var(--u));border-radius:50%;background:#FF5F57}.pv.video-js .pv-bar i:nth-child(2){background:#FEBC2E}.pv.video-js .pv-bar i:nth-child(3){background:#28C840}.pv.video-js .pv-bar span{flex:1;margin:0 calc(4 * var(--u));height:calc(1.5 * var(--u));border-radius:calc(.75 * var(--u));background:#fff;border:1px solid var(--pv-border);color:var(--pv-muted);font-size:calc(.8 * var(--u));display:grid;place-items:center;overflow:hidden;white-space:nowrap}.pv.video-js .pv-panel{position:absolute;left:var(--ox);top:var(--oy);width:calc(27 * var(--u));height:calc(56.25 * var(--u));padding:calc(3.2 * var(--u)) calc(2.4 * var(--u)) calc(5.2 * var(--u)) calc(3.2 * var(--u));box-sizing:border-box;display:flex;flex-direction:column;color:var(--pv-ink);pointer-events:none}.pv.video-js .pv-panel .pv-logo{width:calc(13 * var(--u));margin-bottom:calc(4 * var(--u))}.pv.video-js h1,.pv.video-js p,.pv.video-js ol,.pv.video-js li,.pv.video-js button,.pv.video-js span{margin:0;padding:0;letter-spacing:normal;text-transform:none;font-family:inherit}.pv.video-js img{margin:0;border:0;box-shadow:none;max-width:none}.pv.video-js .pv-eyebrow{color:var(--pv-primary);font:700 calc(.95 * var(--u)) Arial;letter-spacing:.08em;text-transform:uppercase;margin-bottom:calc(.8 * var(--u))}.pv.video-js .pv-panel h1{font:700 calc(2.6 * var(--u)) / 1.12 var(--pv-title-font), Arial;margin:0 0 calc(.9 * var(--u));color:var(--pv-ink)}.pv.video-js .pv-panel p{color:var(--pv-muted);font-size:calc(1.25 * var(--u));line-height:1.4;margin:0 0 calc(2 * var(--u))}.pv.video-js .pv-toc{list-style:none;padding:0;margin:0;border-top:1px solid var(--pv-border);pointer-events:auto}.pv.video-js .pv-toc li{border-bottom:1px solid var(--pv-border);list-style:none}.pv.video-js .pv-toc li::before,.pv.video-js .pv-toc li::marker{content:none}.pv.video-js .pv-toc button{all:unset;box-sizing:border-box;width:100%;display:flex;gap:calc(.9 * var(--u));align-items:center;padding:calc(.7 * var(--u)) calc(.2 * var(--u));cursor:pointer;color:var(--pv-muted);font:calc(1.1 * var(--u)) / 1.3 inherit}.pv.video-js .pv-toc button:focus-visible{outline:2px solid var(--pv-primary);outline-offset:-2px}.pv.video-js .pv-toc .n{width:calc(1.9 * var(--u));height:calc(1.9 * var(--u));border-radius:50%;background:var(--pv-border);display:grid;place-items:center;font:700 calc(.85 * var(--u)) var(--pv-title-font), Arial;flex:none}.pv.video-js .pv-toc li.on button{color:var(--pv-ink);font-weight:600}.pv.video-js .pv-toc li.on .n{background:var(--pv-primary);color:#fff}.pv.video-js .pv-toc button:hover{color:var(--pv-ink)}.pv.video-js .pv-foot{margin-top:auto;color:var(--pv-muted);font-size:calc(.85 * var(--u))}.pv.video-js .pv-cover{position:absolute;inset:0;background:var(--pv-cover);color:#fff;display:none;z-index:2;cursor:pointer}.pv.video-js:not(.vjs-has-started) .pv-cover{display:block}.pv.video-js .pv-cover>div{position:absolute;left:calc(var(--ox) + 6 * var(--u));top:calc(var(--oy) + 5 * var(--u));width:calc(38 * var(--u))}.pv.video-js .pv-cover .pv-mark{position:absolute;left:calc(var(--ox) + 55 * var(--u));top:calc(var(--oy) + 4 * var(--u));width:calc(48 * var(--u))}.pv.video-js .pv-cover .pv-logo{width:calc(14 * var(--u));margin-bottom:calc(12 * var(--u))}.pv.video-js .pv-cover .pv-eyebrow{color:var(--pv-cover-eyebrow)}.pv.video-js .pv-cover h1{font:700 calc(4.6 * var(--u)) / 1.08 var(--pv-title-font), Arial;margin:0 0 calc(1.4 * var(--u));color:#fff}.pv.video-js .pv-cover p{color:var(--pv-cover-sub);font-size:calc(1.8 * var(--u));margin:0 0 calc(2.6 * var(--u))}.pv.video-js .pv-cover b{display:inline-block;background:var(--pv-pill-bg);color:var(--pv-pill-text);border-radius:calc(.7 * var(--u));padding:calc(.8 * var(--u)) calc(1.8 * var(--u));font:700 calc(1.3 * var(--u)) Arial}.pv.video-js .pv-tools{position:absolute;right:calc(100cqw - var(--ox) - 96.5 * var(--u));top:calc(var(--oy) + .9 * var(--u));display:flex;gap:calc(.3 * var(--u));background:var(--pv-surface);border:1px solid var(--pv-border);border-radius:calc(.8 * var(--u));padding:calc(.25 * var(--u));z-index:4}.pv.video-js .pv-tools button{border:0;background:none;padding:calc(.35 * var(--u)) calc(.9 * var(--u));border-radius:calc(.55 * var(--u));font:600 calc(.95 * var(--u)) Arial;color:var(--pv-muted);cursor:pointer}.pv.video-js .pv-tools button[aria-pressed=true]{background:var(--pv-primary);color:#fff}.pv.video-js .pv-tools button:focus-visible{outline:2px solid var(--pv-primary);outline-offset:1px}.pv.video-js .pv-ccwrap{position:relative;display:flex}.pv.video-js .pv-ccmenu{position:absolute;right:0;top:calc(100% + .5 * var(--u));margin:0;padding:calc(.35 * var(--u));list-style:none;background:#fff;border:1px solid var(--pv-border);border-radius:calc(.8 * var(--u));min-width:calc(13 * var(--u));box-shadow:0 calc(1 * var(--u)) calc(2.5 * var(--u)) rgba(21, 27, 36, .16)}.pv.video-js .pv-ccmenu li{padding:calc(.55 * var(--u)) calc(.9 * var(--u));border-radius:calc(.5 * var(--u));font:500 calc(.95 * var(--u)) Arial;color:var(--pv-ink);cursor:pointer;white-space:nowrap;display:flex;justify-content:space-between;gap:calc(1 * var(--u))}.pv.video-js .pv-ccmenu li:hover,.pv.video-js .pv-ccmenu li:focus{background:var(--pv-surface);outline:none}.pv.video-js .pv-ccmenu li[aria-checked=true]{color:var(--pv-primary);font-weight:700}.pv.video-js .pv-ccmenu li[aria-checked=true]::after{content:\"✓\"}.pv.video-js .pv-ccmenu li.sep{height:1px;padding:0;margin:calc(.3 * var(--u)) 0;background:var(--pv-border);cursor:default}.pv.video-js .pv-subs{position:absolute;left:var(--ox);width:calc(100 * var(--u));z-index:1;pointer-events:none;text-align:center;bottom:calc(100cqh - var(--oy) - 51.8 * var(--u));padding:0 calc(6 * var(--u));box-sizing:border-box;transition:bottom .25s}.pv.video-js.vjs-user-inactive.vjs-playing .pv-subs{bottom:calc(100cqh - var(--oy) - 54.4 * var(--u))}.pv.video-js .pv-subs span:not(:empty){display:inline-block;background:rgba(21, 27, 36, .84);color:#fff;border-radius:calc(.5 * var(--u));padding:calc(.35 * var(--u)) calc(1 * var(--u));font:500 calc(1.55 * var(--u)) / 1.35 Arial}.pv.video-js .pv-subs[hidden]{display:none}.pv.video-js .vjs-text-track-display{display:none}.pv.video-js .vjs-control-bar{background:linear-gradient(transparent, rgba(14, 17, 22, .82));height:max(34px, calc(3.6 * var(--u)));font-size:max(10px, calc(1.05 * var(--u)));z-index:3}.pv.video-js .vjs-big-play-button{left:50%;top:50%;transform:translate(-50%, -50%);margin:0;z-index:3;width:calc(7 * var(--u));height:calc(4.6 * var(--u));line-height:calc(4.6 * var(--u));font-size:calc(3 * var(--u));border-radius:calc(.8 * var(--u));background:var(--pv-primary);border:0;opacity:.94}.pv.video-js .vjs-big-play-button .vjs-icon-placeholder:before{line-height:calc(4.6 * var(--u))}.pv.video-js:hover .vjs-big-play-button{opacity:1}.pv.video-js .vjs-big-play-button,.pv.video-js .vjs-big-play-button .vjs-icon-placeholder{color:#fff}.pv.video-js:not(.vjs-has-started) .vjs-big-play-button{background:#fff;opacity:1;box-shadow:0 calc(.8 * var(--u)) calc(2 * var(--u)) rgba(0, 0, 0, .18)}.pv.video-js:not(.vjs-has-started) .vjs-big-play-button .vjs-icon-placeholder{color:var(--pv-primary)}.pv.video-js.vjs-has-started.vjs-paused .vjs-big-play-button{display:block}.pv.video-js.vjs-playing .vjs-big-play-button,.pv.video-js.vjs-seeking .vjs-big-play-button{display:none}"}],"page":{"pagePath":"self-hosting/operations/mongo-to-postgresql","slug":"/self-hosting/operations/mongo-to-postgresql","pageMetadata":{"title":"MongoDB → PostgreSQL migration","description":"Migrate an existing Prisme.ai installation from MongoDB to PostgreSQL for the three structured-data stores (users, permissions, collections).","href":"/self-hosting/operations/mongo-to-postgresql"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Migrate an existing Prisme.ai installation from MongoDB to PostgreSQL for the three structured-data stores (users, permissions, collections).\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{Accordion,AccordionGroup,Check,CodeBlock,CodeGroup,Heading,Info,Note,Step,Steps,Table,Tip,Warning}=_components;if(!Accordion)_missingMdxReference(`Accordion`,true);if(!AccordionGroup)_missingMdxReference(`AccordionGroup`,true);if(!Check)_missingMdxReference(`Check`,true);if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!CodeGroup)_missingMdxReference(`CodeGroup`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Info)_missingMdxReference(`Info`,true);if(!Note)_missingMdxReference(`Note`,true);if(!Step)_missingMdxReference(`Step`,true);if(!Steps)_missingMdxReference(`Steps`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Tip)_missingMdxReference(`Tip`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`This guide migrates the three Prisme.ai structured-data stores (`,_jsx(_components.strong,{children:_jsx(_components.code,{children:`users`})}),`, `,_jsx(_components.strong,{children:_jsx(_components.code,{children:`permissions`})}),` and `,_jsx(_components.strong,{children:_jsx(_components.code,{children:`collections`})}),`) from `,_jsx(_components.strong,{children:`MongoDB`}),` to `,_jsx(_components.strong,{children:`PostgreSQL`}),`. It applies when you already run Prisme.ai on Mongo and want to move to Postgres (the `,_jsx(_components.a,{href:`/self-hosting/databases/postgresql`,children:`recommended engine`}),` for new deployments).`]}),`\n`,_jsxs(_components.p,{children:[`The approach is a `,_jsx(_components.strong,{children:`data reimport`}),`, not a live replication: you stand up a fresh Postgres-backed install, dump the Mongo databases, and load each dump into its Postgres counterpart with a migration script that upserts every document by id.`]}),`\n`,_jsx(Info,{children:_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`The schemas come from the platform, not from the migration.`}),` The relational schema of all three databases is provisioned the clean way: the backends create the `,_jsx(_components.code,{children:`users`}),` and `,_jsx(_components.code,{children:`permissions`}),` tables on startup, and the `,_jsx(_components.code,{children:`collections`}),` schema is generated by the MongoDB platform runtime and applied as `,_jsx(_components.code,{children:`collections.sql`}),`. The migration script `,_jsx(_components.strong,{children:`only loads data`}),` into those existing tables and adapts each value to their real column types; it does not design the schema.`]})}),`\n`,_jsx(Info,{children:_jsxs(_components.p,{children:[`Prisme.ai’s three stores run on a `,_jsx(_components.strong,{children:`single relational engine`}),`; you cannot mix Postgres and Mongo across `,_jsx(_components.code,{children:`users`}),`, `,_jsx(_components.code,{children:`permissions`}),` and `,_jsx(_components.code,{children:`collections`}),`. This migration moves `,_jsx(_components.strong,{children:`all three`}),` at once. See `,_jsx(_components.a,{href:`/self-hosting/databases/postgresql`,children:`Databases / PostgreSQL`}),`.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`overview`,children:`Overview`}),`\n`,_jsxs(Steps,{children:[_jsx(Step,{title:`Deploy the Postgres-backed platform`,children:_jsx(_components.p,{children:`Configure and deploy the core \u0026 apps Helm charts against PostgreSQL, and let the backends create their own tables.`})}),_jsx(Step,{title:`Import the collections SQL schema`,children:_jsxs(_components.p,{children:[`Generate the `,_jsx(_components.code,{children:`collections`}),` schema from the source runtime and apply it so every collection table exists with the correct types and constraints.`]})}),_jsx(Step,{title:`Dump the MongoDB databases`,children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`mongodump`}),` the `,_jsx(_components.code,{children:`users`}),`, `,_jsx(_components.code,{children:`permissions`}),` and `,_jsx(_components.code,{children:`collections`}),` databases.`]})}),_jsx(Step,{title:`Run the migration script`,children:_jsxs(_components.p,{children:[`Load each dump into its Postgres database with `,_jsx(_components.code,{children:`mongo_to_postgres.py`}),`, once per database.`]})})]}),`\n`,_jsx(Heading,{level:`2`,id:`prerequisites`,children:`Prerequisites`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`A running Postgres-backed Prisme.ai install`}),` (see Step 1); the target databases must exist and their connection URLs be known.`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:_jsx(_components.a,{href:`https://www.mongodb.com/docs/database-tools/`,children:`MongoDB Database Tools`})}),` for `,_jsx(_components.code,{children:`mongodump`}),`, to produce the source dumps.`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsxs(_components.strong,{children:[`The PostgreSQL client (`,_jsx(_components.code,{children:`psql`}),`)`]}),`: see `,_jsx(_components.a,{href:`/self-hosting/databases/postgresql`,children:`installing the client`}),`.`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Python 3.9+`}),` with the migration dependencies:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`pip`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` install`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"pymongo>=4\"`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` psycopg2-binary`})]}),`\n`]})})}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`The migration assets`}),`:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.a,{href:`https://gitlab.com/prisme.ai/prisme.ai/-/raw/main/scripts/mongo_to_postgres.py`,children:_jsx(_components.code,{children:`scripts/mongo_to_postgres.py`})}),`: the import script (shipped with the platform repository).`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`collections.sql`}),`: the `,_jsx(_components.code,{children:`collections`}),` schema as SQL DDL, `,_jsx(_components.strong,{children:`generated from your source (Mongo-backed) runtime`}),` (see `,_jsx(_components.a,{href:`#generating-the-collections-schema`,children:`Generating the collections schema`}),`). It carries every collection table with its real types, constraints and defaults.`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`Run the whole migration against an `,_jsx(_components.strong,{children:`empty`}),` or freshly-initialized Postgres target. The script is idempotent (safe to re-run), but the source of truth here is the Mongo dump; do not point it at a Postgres database that already holds diverging data.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`1-deploy-the-postgres-backed-platform`,children:`1. Deploy the Postgres-backed platform`}),`\n`,_jsxs(_components.p,{children:[`Configure and deploy the `,_jsx(_components.strong,{children:`core`}),` and `,_jsx(_components.strong,{children:`apps`}),` Helm charts with the three storage drivers set to `,_jsx(_components.code,{children:`postgresql`}),` (see `,_jsx(_components.a,{href:`/self-hosting/databases/postgresql#configuration`,children:`Databases / PostgreSQL: Configuration`}),` and `,_jsx(_components.a,{href:`/self-hosting/kubernetes/helm#6-postgresql`,children:`Helm install: PostgreSQL`}),`).`]}),`\n`,_jsxs(_components.p,{children:[`Then verify the platform is healthy `,_jsx(_components.strong,{children:`before importing any data`}),`:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Every service is up \u0026 running`}),`: `,_jsx(_components.code,{children:`prismeai-api-gateway`}),`, `,_jsx(_components.code,{children:`prismeai-workspaces`}),`, `,_jsx(_components.code,{children:`prismeai-events`}),`, `,_jsx(_components.code,{children:`prismeai-runtime`}),`, and the apps.`]}),`\n`,_jsxs(_components.li,{children:[_jsxs(_components.strong,{children:[`The `,_jsx(_components.code,{children:`users`}),` and `,_jsx(_components.code,{children:`permissions`}),` schemas are initialized.`]}),` The backends create their own tables on first startup:`,`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`prismeai-api-gateway`}),` auto-creates the `,_jsx(_components.strong,{children:_jsx(_components.code,{children:`users`})}),` tables (accounts, organizations, memberships, roles, API keys…).`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`prismeai-workspaces`}),` auto-creates the `,_jsx(_components.strong,{children:_jsx(_components.code,{children:`permissions`})}),` tables (workspace-level RBAC).`]}),`\n`]}),`\n`]}),`\n`]}),`\n`,_jsx(Note,{children:_jsxs(_components.p,{children:[`Let the backends fully boot so these tables exist. The migration script adapts to the `,_jsx(_components.strong,{children:`real`}),` column types and defaults of the target tables; those must be in place first.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`2-import-the-collections-sql-schema`,children:`2. Import the collections SQL schema`}),`\n`,_jsxs(_components.p,{children:[`Unlike `,_jsx(_components.code,{children:`users`}),` and `,_jsx(_components.code,{children:`permissions`}),`, the `,_jsx(_components.strong,{children:_jsx(_components.code,{children:`collections`})}),` tables are not created by a backend on startup; they are provisioned lazily as platform workspaces are imported. To get the schema the clean way without replaying that whole path, generate it from your source runtime and apply it to the target.`]}),`\n`,_jsx(Heading,{level:`3`,id:`generating-the-collections-schema`,children:`Generating the collections schema`}),`\n`,_jsxs(_components.p,{children:[`The `,_jsx(_components.strong,{children:`source`}),` platform (the runtime still running on MongoDB) exposes an internal endpoint that emits the full collections schema as SQL DDL. Generate `,_jsx(_components.code,{children:`collections.sql`}),` from a running runtime pod:`]}),`\n`,_jsxs(Steps,{children:[_jsx(Step,{title:`Exec into a runtime pod`,children:_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`kubectl`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` exec`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -it`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` deploy/prismeai-runtime`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` sh`})]}),`\n`]})})})}),_jsx(Step,{title:`Fetch the schema`,children:_jsx(CodeBlock,{filename:``,numberOfLines:`2`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`2`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`curl`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -H`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"x-prismeai-api-key: `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$INTERNAL_API_KEY`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` http://localhost/sys/collections/schema`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` >`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` collections.sql`})]}),`\n`]})})})})]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`$INTERNAL_API_KEY`}),` is the runtime’s internal API key, already present in the pod’s environment, which is why the call is made from `,_jsx(_components.strong,{children:`inside`}),` the runtime. The `,_jsx(_components.code,{children:`/sys/collections/schema`}),` route is internal-only and rejects any request without the matching key. Copy the resulting `,_jsx(_components.code,{children:`collections.sql`}),` out of the pod to where you will run `,_jsx(_components.code,{children:`psql`}),` (e.g. `,_jsx(_components.code,{children:`kubectl cp \u003cpod>:/path/collections.sql ./collections.sql`}),`).`]}),`\n`,_jsx(Heading,{level:`3`,id:`applying-the-schema`,children:`Applying the schema`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`psql`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$COLLECTIONS_PG_URL`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` ./collections.sql`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`This creates every collection table with the exact types, constraints and defaults the platform expects, so the migration only has to load rows into them.`}),`\n`,_jsx(Info,{children:_jsxs(_components.p,{children:[_jsx(_components.code,{children:`$COLLECTIONS_PG_URL`}),` must include the database name `,_jsx(_components.strong,{children:`in the URL`}),` (e.g. `,_jsx(_components.code,{children:`postgres://user:pass@host:5432/collections?sslmode=require`}),`). With `,_jsx(_components.code,{children:`psql`}),`, a separate `,_jsx(_components.code,{children:`-d name`}),` flag `,_jsx(_components.strong,{children:`replaces`}),` the whole connection string from the URL; put the database in the URL instead. See `,_jsx(_components.a,{href:`#psql-connects-to-the-wrong-server`,children:`psql troubleshooting`}),`.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`3-dump-the-mongodb-databases`,children:`3. Dump the MongoDB databases`}),`\n`,_jsx(_components.p,{children:`Dump the three source databases from your existing Mongo cluster into a single directory:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`3`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`3`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`mongodump`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --uri=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$MONGO_URI`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --db`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` users`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --out=./mongodump`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`mongodump`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --uri=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$MONGO_URI`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --db`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` permissions`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --out=./mongodump`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`mongodump`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --uri=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$MONGO_URI`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --db`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` collections`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --out=./mongodump`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`This produces `,_jsx(_components.code,{children:`./mongodump/\u003cdb>/\u003ccollection>.bson`}),` (plus `,_jsx(_components.code,{children:`.metadata.json`}),` sidecars), exactly the layout the migration script expects.`]}),`\n`,_jsx(Tip,{children:_jsxs(_components.p,{children:[`Add `,_jsx(_components.code,{children:`--readPreference=secondary`}),` when dumping a production cluster so the dump reads from a replica instead of the primary.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`4-run-the-migration-script`,children:`4. Run the migration script`}),`\n`,_jsxs(_components.p,{children:[`Load each dump into its Postgres database, `,_jsx(_components.strong,{children:`once per database`}),`. Point `,_jsx(_components.code,{children:`--mongo-db`}),` at the source Mongo database (a sub-directory of the dump) and `,_jsx(_components.code,{children:`--pg-database`}),` at the target Postgres database:`]}),`\n`,_jsxs(CodeGroup,{children:[_jsx(CodeBlock,{filename:`users`,numberOfLines:`6`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`6`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`python`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` ./scripts/mongo_to_postgres.py`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --dump-dir`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` ./mongodump`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --mongo-db`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` users`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --pg-dsn`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$PG_URL`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --pg-database`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` users`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --pg-schema`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` public`})]}),`\n`]})})}),_jsx(CodeBlock,{filename:`permissions`,numberOfLines:`6`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`6`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`python`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` ./scripts/mongo_to_postgres.py`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --dump-dir`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` ./mongodump`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --mongo-db`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` permissions`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --pg-dsn`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$PG_URL`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --pg-database`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` permissions`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --pg-schema`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` public`})]}),`\n`]})})}),_jsx(CodeBlock,{filename:`collections`,numberOfLines:`6`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`6`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`python`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` ./scripts/mongo_to_postgres.py`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --dump-dir`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` ./mongodump`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --mongo-db`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` collections`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --pg-dsn`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$PG_URL`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --pg-database`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` collections`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D7BA7D`},children:` \\\\`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --pg-schema`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` public`})]}),`\n`]})})})]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`--pg-database`}),` overrides the database name in `,_jsx(_components.code,{children:`--pg-dsn`}),`, so you can keep a single generic `,_jsx(_components.code,{children:`$PG_URL`}),` (host / user / password) and only change the target database between runs.`]}),`\n`,_jsx(Check,{children:_jsxs(_components.p,{children:[`Each run prints, per collection, the primary key used, document count and the number of rows upserted, e.g. `,_jsx(_components.code,{children:`-> upserted 1240 row(s)`}),`. Empty and excluded collections are reported as skipped.`]})}),`\n`,_jsx(Heading,{level:`3`,id:`how-the-script-works`,children:`How the script works`}),`\n`,_jsxs(AccordionGroup,{children:[_jsxs(Accordion,{title:`Loads into the existing schema`,id:`loads-into-the-existing-schema`,children:[_jsxs(_components.p,{children:[`When a table already exists, created by the backends (`,_jsx(_components.code,{children:`users`}),`, `,_jsx(_components.code,{children:`permissions`}),`) or by `,_jsx(_components.code,{children:`collections.sql`}),`, the script reads its `,_jsx(_components.strong,{children:`real`}),` column types, defaults and constraints from `,_jsx(_components.code,{children:`information_schema`}),` and coerces every Mongo value to match: strings to `,_jsx(_components.code,{children:`timestamptz`}),`, epoch numbers to dates, objects to `,_jsx(_components.code,{children:`jsonb`}),`, string arrays to `,_jsx(_components.code,{children:`text[]`}),`, and so on. This is the reliable path, and the reason you should provision `,_jsx(_components.code,{children:`collections.sql`}),` up front.`]}),_jsxs(_components.p,{children:[`For a collection whose table is `,_jsx(_components.strong,{children:`missing`}),`, the script falls back to `,_jsx(_components.strong,{children:`inferring`}),` a schema from the data it reads and creating the table itself. Treat this as a last resort: the inferred types are guessed from sample values and can be wrong, causing failures at insertion or at read time (see the warning in `,_jsx(_components.a,{href:`#2-import-the-collections-sql-schema`,children:`Step 2`}),`). Provision the real schema for every important table instead of relying on this fallback.`]})]}),_jsx(Accordion,{title:`Idempotent: safe to re-run`,id:`idempotent-safe-to-re-run`,children:_jsxs(_components.p,{children:[`Rows are UPSERTed on their primary key (`,_jsx(_components.code,{children:`INSERT … ON CONFLICT (pk) DO UPDATE`}),`), so ids are preserved and re-running never duplicates rows nor errors. If a run is interrupted, just run it again.`]})}),_jsx(Accordion,{title:`Primary key detection`,id:`primary-key-detection`,children:_jsxs(_components.p,{children:[`The primary key is `,_jsx(_components.strong,{children:_jsx(_components.code,{children:`_id`})}),` if present, otherwise `,_jsx(_components.strong,{children:_jsx(_components.code,{children:`id`})}),`, decided per collection. A non-empty collection with neither is treated as invalid and aborts the run (override with `,_jsx(_components.code,{children:`--skip-invalid`}),`). Empty collections are skipped.`]})}),_jsx(Accordion,{title:`camelCase → snake_case column names`,id:`camelcase-snake-case-column-names`,children:_jsxs(_components.p,{children:[`Mongo field names are converted to `,_jsx(_components.code,{children:`snake_case`}),` to match the platform ORM (e.g. `,_jsx(_components.code,{children:`authData`}),` → `,_jsx(_components.code,{children:`auth_data`}),`, `,_jsx(_components.code,{children:`expiresAt`}),` → `,_jsx(_components.code,{children:`expires_at`}),`); `,_jsx(_components.code,{children:`_id`}),` is kept as-is. Use `,_jsx(_components.code,{children:`--column-naming preserve`}),` to keep the original Mongo names instead.`]})}),_jsx(Accordion,{title:`NOT NULL defaults`,id:`not-null-defaults`,children:_jsxs(_components.p,{children:[`When a `,_jsx(_components.code,{children:`NOT NULL`}),` column has no value in the Mongo document, the script applies the table’s real Postgres `,_jsx(_components.code,{children:`DEFAULT`}),` (any type), falling back to `,_jsx(_components.code,{children:`[]`}),` for arrays and `,_jsx(_components.code,{children:`false`}),` for booleans, matching the ORM defaults that Mongo documents don’t store.`]})}),_jsxs(Accordion,{title:`Excluding rows or whole collections`,id:`excluding-rows-or-whole-collections`,children:[_jsxs(_components.p,{children:[_jsx(_components.code,{children:`--exclude`}),` skips data at two levels:`]}),_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:_jsx(_components.code,{children:`collection:field=value`})}),`: skip matching documents. Some rows are seeded by the API at startup and would collide with the dump on a secondary unique constraint; the defaults skip those platform-workspace rows.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:_jsx(_components.code,{children:`collection`})}),` (bare name): skip an entire collection, before it is even read. Useful for temp/cache collections you don’t want in Postgres (e.g. `,_jsx(_components.code,{children:`--exclude '\u003cworkspaceId>/atlasReportsTemp'`}),`, using the decoded name).`]}),`\n`]}),_jsxs(_components.p,{children:[`Both forms are repeatable and comma-separated; anything you pass is `,_jsx(_components.strong,{children:`added`}),` to the defaults.`]})]})]}),`\n`,_jsx(Heading,{level:`3`,id:`options-reference`,children:`Options reference`}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Flag`}),_jsx(_components.th,{children:`Purpose`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`--dump-dir`})}),_jsxs(_components.td,{children:[`Path to the `,_jsx(_components.code,{children:`mongodump`}),` output directory.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`--mongo-db`})}),_jsxs(_components.td,{children:[`Source Mongo database(s): the `,_jsx(_components.code,{children:`\u003cdump-dir>/\u003cdb>`}),` sub-directory to import. Comma-separated.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`--pg-dsn`})}),_jsxs(_components.td,{children:[`Target Postgres DSN (or `,_jsx(_components.code,{children:`PG_DSN`}),` env var).`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`--pg-database`})}),_jsxs(_components.td,{children:[`Target Postgres database, overrides the `,_jsx(_components.code,{children:`/dbname`}),` of `,_jsx(_components.code,{children:`--pg-dsn`}),`.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`--pg-schema`})}),_jsxs(_components.td,{children:[`Target Postgres schema (default `,_jsx(_components.code,{children:`public`}),`).`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`--collections`})}),_jsx(_components.td,{children:`Import only these collections (comma-separated).`})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`--exclude`})}),_jsxs(_components.td,{children:[`Skip data: `,_jsx(_components.code,{children:`collection:field=value`}),` skips matching documents, a bare `,_jsx(_components.code,{children:`collection`}),` skips the whole collection. Repeatable; added to the platform-seed defaults.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`--column-naming`})}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`snake`}),` (default) or `,_jsx(_components.code,{children:`preserve`}),`.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`--skip-invalid`})}),_jsxs(_components.td,{children:[`Skip non-empty collections that have no `,_jsx(_components.code,{children:`_id`}),`/`,_jsx(_components.code,{children:`id`}),` instead of aborting.`]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:_jsx(_components.code,{children:`--batch-size`})}),_jsxs(_components.td,{children:[`Rows per upsert batch (default `,_jsx(_components.code,{children:`1000`}),`).`]})]})]})]}),`\n`,_jsx(Heading,{level:`2`,id:`verification`,children:`Verification`}),`\n`,_jsx(_components.p,{children:`After importing all three databases:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Row counts`}),`: spot-check a few collections against Mongo:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`4`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`4`,children:[_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Mongo`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`mongosh`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`$MONGO_URI`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`/users\"`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` --eval`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'db.Users.countDocuments()'`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# Postgres`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`psql`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:' \"${'}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`PG_URL`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`%/*`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`}/users\"`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -c`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'SELECT count(*) FROM \"Users\";'`})]}),`\n`]})})}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Log in`}),` to the platform as an existing user and confirm organizations, workspaces and permissions resolve correctly.`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Open a workspace`}),` that uses collections and confirm its data is present.`]}),`\n`]}),`\n`]}),`\n`,_jsx(Note,{children:_jsxs(_components.p,{children:[`Table and column identifiers are case-sensitive in Postgres and quoted by the ORM (e.g. `,_jsx(_components.code,{children:`\"Users\"`}),`, `,_jsx(_components.code,{children:`\"AccessTokens\"`}),`). Quote them in `,_jsx(_components.code,{children:`psql`}),` queries.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`troubleshooting`,children:`Troubleshooting`}),`\n`,_jsxs(AccordionGroup,{children:[_jsxs(Accordion,{title:`psql connects to the wrong server`,id:`psql-connects-to-the-wrong-server`,children:[_jsxs(_components.p,{children:[_jsx(_components.code,{children:`connection to server on socket \"/tmp/.s.PGSQL.5432\" failed`}),` means `,_jsx(_components.code,{children:`psql`}),` ignored your connection URL and fell back to the local socket. This happens when you pass both a URL `,_jsx(_components.strong,{children:`and`}),` a bare `,_jsx(_components.code,{children:`-d dbname`}),`; the `,_jsx(_components.code,{children:`-d`}),` replaces the whole connection string. Put the database `,_jsx(_components.strong,{children:`in the URL`}),` instead:`]}),_jsx(CodeBlock,{filename:``,numberOfLines:`1`,language:`shellscript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`shellscript`,children:_jsxs(_components.code,{language:`shellscript`,numberOfLines:`1`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#DCDCAA`},children:`psql`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"postgres://user:pass@host:5432/collections?sslmode=require\"`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` -f`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` ./collections.sql`})]}),`\n`]})})}),_jsxs(_components.p,{children:[`Also confirm the variable is set (`,_jsx(_components.code,{children:`echo \"$COLLECTIONS_PG_URL\"`}),`); an empty value produces the same fallback.`]})]}),_jsx(Accordion,{title:`null value in column … violates not-null constraint`,id:`null-value-in-column-violates-not-null-constraint`,children:_jsxs(_components.p,{children:[`A `,_jsx(_components.code,{children:`NOT NULL`}),` column received no value and has no usable default. The script auto-fills DB defaults, empty arrays and `,_jsx(_components.code,{children:`false`}),` booleans; anything else means a genuinely missing required field or a type that couldn’t be coerced. The script prints a one-line diagnostic naming the field, column and reason just before the failure; use it to identify the field.`]})}),_jsx(Accordion,{title:`duplicate key value violates unique constraint`,id:`duplicate-key-value-violates-unique-constraint`,children:_jsxs(_components.p,{children:[`A row already exists in Postgres (seeded by the API at startup) that collides with the dump on a `,_jsx(_components.strong,{children:`secondary unique constraint`}),` (not the primary key). Exclude the seeded rows with `,_jsx(_components.code,{children:`--exclude`}),`. The platform-workspace roles are excluded by default (`,_jsx(_components.code,{children:`roles:subjectId=platform`}),`).`]})}),_jsx(Accordion,{title:`Aborting: invalid collection(s)`,id:`aborting-invalid-collections`,children:_jsxs(_components.p,{children:[`A non-empty collection has neither `,_jsx(_components.code,{children:`_id`}),` nor `,_jsx(_components.code,{children:`id`}),`, so no stable key exists to upsert on. Inspect the collection; if it is genuinely disposable, re-run with `,_jsx(_components.code,{children:`--skip-invalid`}),`.`]})})]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Order matters.`}),` Deploy and let the backends create the `,_jsx(_components.code,{children:`users`}),`/`,_jsx(_components.code,{children:`permissions`}),` tables (Step 1) and import the `,_jsx(_components.code,{children:`collections`}),` schema (Step 2) `,_jsx(_components.strong,{children:`before`}),` running the script (Step 4). The importer adapts to the real column types and defaults of the target tables, so those tables must exist first.`]})})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"MongoDB → PostgreSQL migration","description":"Migrate an existing Prisme.ai installation from MongoDB to PostgreSQL for the three structured-data stores (users, permissions, collections).","href":"/self-hosting/operations/mongo-to-postgresql"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Overview","slug":"overview","depth":2,"children":[]},{"title":"Prerequisites","slug":"prerequisites","depth":2,"children":[]},{"title":"1. Deploy the Postgres-backed platform","slug":"1-deploy-the-postgres-backed-platform","depth":2,"children":[]},{"title":"2. Import the collections SQL schema","slug":"2-import-the-collections-sql-schema","depth":2,"children":[{"title":"Generating the collections schema","slug":"generating-the-collections-schema","depth":3,"children":[]},{"title":"Applying the schema","slug":"applying-the-schema","depth":3,"children":[]}]},{"title":"3. Dump the MongoDB databases","slug":"3-dump-the-mongodb-databases","depth":2,"children":[]},{"title":"4. Run the migration script","slug":"4-run-the-migration-script","depth":2,"children":[{"title":"How the script works","slug":"how-the-script-works","depth":3,"children":[]},{"title":"Options reference","slug":"options-reference","depth":3,"children":[]}]},{"title":"Verification","slug":"verification","depth":2,"children":[]},{"title":"Troubleshooting","slug":"troubleshooting","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":["/_mintlify/custom/prismeai/7f6a1ef93dff131f/tutorials/player.js"],"subdomain":"prismeai","siteName":"Prisme.ai","title":"MongoDB → PostgreSQL migration - Prisme.ai","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-11-12T19:23:00.884Z","originalFileLocation":"self-hosting/operations/mongo-to-postgresql.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Migrate an existing Prisme.ai installation from MongoDB to PostgreSQL for the three structured-data stores (users, permissions, collections).\">\u003cmeta data-mint-head name=\"keywords\" content=\"sovereign agentic platform, plateforme agentique souveraine, AI Information System, enterprise AI platform, AI agents, agent governance, traceable AI, cloud agnostic, LLM agnostic, agentic workflows\">\u003cmeta data-mint-head name=\"application-name\" content=\"Prisme.ai\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003cmeta data-mint-head name=\"robots\" content=\"index, follow\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/prismeai/sbDkziZfjieAR-LF/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/prismeai/sbDkziZfjieAR-LF/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/prismeai/sbDkziZfjieAR-LF/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/prismeai/sbDkziZfjieAR-LF/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/prismeai/sbDkziZfjieAR-LF/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/prismeai/sbDkziZfjieAR-LF/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/prismeai/sbDkziZfjieAR-LF/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/prismeai/sbDkziZfjieAR-LF/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/prismeai/sbDkziZfjieAR-LF/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"MongoDB → PostgreSQL migration - Prisme.ai\">\u003cmeta data-mint-head property=\"og:description\" content=\"Migrate an existing Prisme.ai installation from MongoDB to PostgreSQL for the three structured-data stores (users, permissions, collections).\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Prisme.ai Documentation\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.prisme.ai/self-hosting/operations/mongo-to-postgresql\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://prismeai.mintlify.site/_mintlify/api/og/v2?division=Operations\u0026amp;title=MongoDB+%E2%86%92+PostgreSQL+migration\u0026amp;description=Migrate+an+existing+Prisme.ai+installation+from+MongoDB+to+PostgreSQL+for+the+three+structured-data+stores+%28users%2C+permissions%2C+collections%29.\u0026amp;theme=04f9745faa1f89452b755e15\u0026amp;signature=36ae704657b6e43835db640912facff8a02036d8cd380ae894676e7820ba4893\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"MongoDB → PostgreSQL migration - Prisme.ai\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Migrate an existing Prisme.ai installation from MongoDB to PostgreSQL for the three structured-data stores (users, permissions, collections).\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://prismeai.mintlify.site/_mintlify/api/og/v2?division=Operations\u0026amp;title=MongoDB+%E2%86%92+PostgreSQL+migration\u0026amp;description=Migrate+an+existing+Prisme.ai+installation+from+MongoDB+to+PostgreSQL+for+the+three+structured-data+stores+%28users%2C+permissions%2C+collections%29.\u0026amp;theme=04f9745faa1f89452b755e15\u0026amp;signature=36ae704657b6e43835db640912facff8a02036d8cd380ae894676e7820ba4893\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/prismeai/sbDkziZfjieAR-LF/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Prisme.ai\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#255BE0\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.prisme.ai/self-hosting/operations/mongo-to-postgresql\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/self-hosting/operations/mongo-to-postgresql.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.prisme.ai/#organization\",\"name\":\"Prisme.ai\",\"url\":\"https://docs.prisme.ai\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/prismeai/_sSeZNUvs7sBNa3K/logo/light.svg?fit=max\u0026auto=format\u0026n=_sSeZNUvs7sBNa3K\u0026q=85\u0026s=4361458c99ac06f7a551020a022b802c\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.prisme.ai#website\",\"name\":\"Prisme.ai\",\"url\":\"https://docs.prisme.ai\",\"publisher\":{\"@id\":\"https://docs.prisme.ai/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.prisme.ai/self-hosting/operations/mongo-to-postgresql#webpage\",\"url\":\"https://docs.prisme.ai/self-hosting/operations/mongo-to-postgresql\",\"name\":\"MongoDB → PostgreSQL migration\",\"description\":\"Migrate an existing Prisme.ai installation from MongoDB to PostgreSQL for the three structured-data stores (users, permissions, collections).\",\"dateModified\":\"2026-11-12T19:23:00.884Z\",\"isPartOf\":{\"@id\":\"https://docs.prisme.ai#website\"},\"breadcrumb\":{\"@id\":\"https://docs.prisme.ai/self-hosting/operations/mongo-to-postgresql#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.prisme.ai/self-hosting/operations/mongo-to-postgresql#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Operations\",\"item\":\"https://docs.prisme.ai/self-hosting/operations/migration-v27\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MongoDB → PostgreSQL migration\",\"item\":\"https://docs.prisme.ai/self-hosting/operations/mongo-to-postgresql\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.prisme.ai/self-hosting/operations/mongo-to-postgresql#article\",\"headline\":\"MongoDB → PostgreSQL migration\",\"name\":\"MongoDB → PostgreSQL migration\",\"description\":\"Migrate an existing Prisme.ai installation from MongoDB to PostgreSQL for the three structured-data stores (users, permissions, collections).\",\"url\":\"https://docs.prisme.ai/self-hosting/operations/mongo-to-postgresql\",\"mainEntityOfPage\":{\"@id\":\"https://docs.prisme.ai/self-hosting/operations/mongo-to-postgresql#webpage\"},\"dateModified\":\"2026-11-12T19:23:00.884Z\",\"publisher\":{\"@id\":\"https://docs.prisme.ai/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.prisme.ai#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Prisme.ai\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Prisme.ai\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/self-hosting/operations/mongo-to-postgresql.md","siteName":"Prisme.ai","nav":{"global":{"anchors":[{"anchor":"Blog","icon":"newspaper","href":"https://blog.prisme.ai"},{"anchor":"Legacy Documentation","icon":"clock-rotate-left","href":"https://prismeai-legacy.mintlify.app/"}]},"tabs":[{"tab":"Home","pages":[{"title":"Home","href":"/home"}]},{"tab":"Get Started","pages":[{"title":"Get Started","href":"/get-started/home"}]},{"tab":"Products","pages":[{"title":"Products","href":"/products/overview"}]},{"tab":"API Reference","pages":[{"title":"API Reference","href":"/api-reference/introduction"}]},{"tab":"App Store","pages":[{"title":"App Store","href":"/apps-store/overview"}]},{"tab":"Self-Hosting","groups":[{"group":"Overview","pages":[{"title":"Self-Hosting Overview","href":"/self-hosting/overview"},{"title":"Requirements","href":"/self-hosting/requirements"}]},{"group":"Installation","pages":[{"title":"Installation Overview","href":"/self-hosting/kubernetes/overview"},{"title":"Install Prisme.ai with Helm","href":"/self-hosting/kubernetes/helm"},{"group":"Cloud Providers","pages":[{"title":"Deploying Prisme.ai on AWS","href":"/self-hosting/cloud/aws"},{"title":"Deploying Prisme.ai on Azure","href":"/self-hosting/cloud/azure"},{"title":"Deploying Prisme.ai on GCP","href":"/self-hosting/cloud/gcp"},{"title":"Deploying Prisme.ai on OVHcloud","href":"/self-hosting/cloud/ovh"},{"title":"Deploying Prisme.ai on OpenShift","href":"/self-hosting/cloud/openshift"}]},{"title":"Configuration","href":"/self-hosting/kubernetes/configuration"},{"title":"Install products","href":"/self-hosting/install-products"},{"title":"Kubernetes Resources \u0026 Autoscaling","href":"/self-hosting/kubernetes/resources"},{"title":"Environment Variables Reference","href":"/self-hosting/kubernetes/environment-variables"},{"title":"Turn on mobile push notifications","href":"/self-hosting/configuration/push-notifications"}]},{"group":"Databases","pages":[{"title":"Databases Overview","href":"/self-hosting/databases/overview"},{"title":"PostgreSQL","href":"/self-hosting/databases/postgresql"},{"title":"MongoDB","href":"/self-hosting/databases/mongodb"},{"title":"Elasticsearch or OpenSearch","href":"/self-hosting/databases/elasticsearch"},{"title":"Push events to Logstash","href":"/self-hosting/databases/logstash"},{"title":"Redis","href":"/self-hosting/databases/redis"}]},{"group":"Production Readiness","pages":[{"title":"Requirements","href":"/self-hosting/production-readiness/requirements"},{"title":"Monitoring thresholds","href":"/self-hosting/production-readiness/monitoring-thresholds"}]},{"group":"Entreprise Services","pages":[{"title":"Authentication \u0026 SSO Integration","href":"/self-hosting/entreprise/authentication"},{"title":"Permissions Management","href":"/self-hosting/entreprise/permissions"},{"title":"Functions Microservice","href":"/self-hosting/entreprise/functions"},{"title":"Crawler \u0026 SearchEngine Microservices","href":"/self-hosting/entreprise/crawler-searchengine"}]},{"group":"Operations","pages":[{"title":"Migration v27","description":"Step-by-step guide for migrating an existing Prisme.ai installation from legacy products (Knowledges, AI Store) to the new v27 platform products (Agent Creator, LLM Gateway, Storage)","href":"/self-hosting/operations/migration-v27"},{"title":"MongoDB → PostgreSQL migration","href":"/self-hosting/operations/mongo-to-postgresql"},{"title":"Updates","description":"Upgrade a self-hosted Prisme.ai platform: bump the service image tags, update the products from the Platform workspace, and verify the imports.","href":"/self-hosting/operations/updates"},{"title":"Backup \u0026 Restore","href":"/self-hosting/operations/backup"},{"title":"Recover a Lost Encryption Key","href":"/self-hosting/operations/encryption-keys"},{"title":"Scaling","href":"/self-hosting/operations/scaling"},{"title":"Network Policies","href":"/self-hosting/kubernetes/network-policies"},{"title":"Testing a deployment","href":"/self-hosting/operations/testing"}]}]},{"tab":"Resources","pages":[{"title":"Resources","href":"/resources/adoption-governance/overview"}]}]},"basePath":"","title":"MongoDB → PostgreSQL migration - Prisme.ai","deploymentId":"dpl_HhUetB7eHHDAmK9T1Teip38TgFx9","buildId":"dpl_HhUetB7eHHDAmK9T1Teip38TgFx9","dynamics":[],"chunks":[]}