# Data flow — prisma/prisma

> Canonical page: https://codevetter.com/unpack/prisma/data-flow

# Data flow — prisma/prisma

Scanned commit dd867230cd8fe08d203b395999f20b4e717fe10b (2026-09-22). Generated by codevetter codevetter 1.12.0 on 2026-09-22.

Authoring starts in prisma.config.ts, where defineConfig binds a family, target, adapter, driver, and extensions to a contract source. Emit loads that source, enriches it with component descriptors, round-trips it through the target serializer, and writes a canonical JSON document plus a generated contract.d.ts. At runtime the Postgres client revalidates that JSON into a typed contract, and the SQL runtime lowers a query plan to SQL, encodes parameters, checks the marker, and decodes rows. Schema changes are a separate pipeline: introspect the database, plan a contract-space aggregate, and apply operations under a class policy. CLI telemetry is a side channel that forks a sender after the command settles.
- Postgres defineConfig calls core defineConfig with family sql, target postgres, adapter postgresAdapter, driver postgresDriver, the caller extensions array, and a normalized contract config. Output defaults beside the first contract input when the caller omits it. — [packages/3-extensions/postgres/src/config/define-config.ts#L65-L78](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/3-extensions/postgres/src/config/define-config.ts#L65-L78) [packages/1-framework/1-core/config/src/config-types.ts#L116-L140](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/1-framework/1-core/config/src/config-types.ts#L116-L140)
- executeContractEmit is the single publication path for the CLI and the Vite plugin. It requires config.contract, a source.load function, and an output path; builds a control stack; calls source.load with composed extension ids, authoring contributions, codec lookup, and capabilities; then enrichContract, target serializeContract, and family deserializeContract before emit. — [packages/1-framework/3-tooling/cli/src/control-api/operations/contract-emit.ts#L221-L376](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/1-framework/3-tooling/cli/src/control-api/operations/contract-emit.ts#L221-L376)
- @internal/emitter emit rejects the call unless to-one relations declare nullability, canonicalizes with schemaVersion "1" via the target serializeContract hook, stamps a _generated warning, and returns contractJson, prettier-formatted contract.d.ts, storageHash, optional executionHash, and profileHash. — [packages/1-framework/3-tooling/emitter/src/emit.ts#L11-L85](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/1-framework/3-tooling/emitter/src/emit.ts#L11-L85)
- The emit JSDoc says publication is serialized per output JSON path by queueEmitByOutput (last submission wins) and that publishContractArtifactPair stages temp files, renames contract.d.ts before contract.json, and tries to restore the previous pair if a rename fails. — [packages/1-framework/3-tooling/cli/src/control-api/operations/contract-emit.ts#L221-L240](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/1-framework/3-tooling/cli/src/control-api/operations/contract-emit.ts#L221-L240)
- postgres() either serializes an in-memory contract or accepts contractJson, then always deserializes through PostgresContractSerializer so the runtime object is the validated form. A url binding becomes a pg Pool (connectionTimeoutMillis default 20000, idleTimeoutMillis default 30000) wrapped in suppressIdleConnectionErrors. — [packages/3-extensions/postgres/src/runtime/postgres.ts#L121-L153](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/3-extensions/postgres/src/runtime/postgres.ts#L121-L153) [packages/3-extensions/postgres/src/runtime/postgres.ts#L162-L186](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/3-extensions/postgres/src/runtime/postgres.ts#L162-L186)
- sql() builds a BuilderContext from contract capabilities, query operation types, target, storageHash, and mutation defaults, then returns a Proxy: the first key is a storage namespace id, the second is a table resolved by resolveTableInNamespace and wrapped in TableProxyImpl. — [packages/2-sql/4-lanes/sql-builder/src/runtime/sql.ts#L16-L64](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/2-sql/4-lanes/sql-builder/src/runtime/sql.ts#L16-L64)
- queryAgainstQueryable validates the codec registry once, calls prepareQueryExecution, buildDecodeContext, and streamRows. prepareOperation, for a not-yet-lowered plan, runs compilePlan, lowerToDraft, a SqlParamRefMutator before-hook, and encodeParams. streamRows then setupDriverExecution, runQueryWithMiddleware, and decodeRow. — [packages/2-sql/5-runtime/src/sql-runtime.ts#L475-L509](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/2-sql/5-runtime/src/sql-runtime.ts#L475-L509) [packages/2-sql/5-runtime/src/sql-runtime.ts#L513-L534](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/2-sql/5-runtime/src/sql-runtime.ts#L513-L534) [packages/2-sql/5-runtime/src/sql-runtime.ts#L384-L429](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/2-sql/5-runtime/src/sql-runtime.ts#L384-L429)
- verifyMarker reads the family marker. If the marker is absent it logs CONTRACT.MARKER_MISSING and returns. If storageHash or profileHash differs it logs CONTRACT.MARKER_MISMATCH and returns. It does not throw, so execution continues. The first call is single-flighted on verifyMarkerPromise unless verifyMarker was set to false. — [packages/2-sql/5-runtime/src/sql-runtime.ts#L371-L377](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/2-sql/5-runtime/src/sql-runtime.ts#L371-L377) [packages/2-sql/5-runtime/src/sql-runtime.ts#L913-L944](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/2-sql/5-runtime/src/sql-runtime.ts#L913-L944)
- executeDbUpdate uses policy classes additive, widening, and destructive and delegates to executeRun. db-run.ts documents the strategy as introspect then planMigration, and imports buildContractSpaceAggregate, planMigration, and runMigration. In apply mode without acceptDataLoss or consent, guardDestructiveChanges pre-plans and returns DESTRUCTIVE_CHANGES with databaseName and planHash. — [packages/1-framework/3-tooling/cli/src/control-api/operations/db-update.ts#L17-L92](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/1-framework/3-tooling/cli/src/control-api/operations/db-update.ts#L17-L92) [packages/1-framework/3-tooling/cli/src/control-api/operations/db-update.ts#L102-L130](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/1-framework/3-tooling/cli/src/control-api/operations/db-update.ts#L102-L130) [packages/1-framework/3-tooling/cli/src/control-api/operations/db-run.ts#L1-L52](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/1-framework/3-tooling/cli/src/control-api/operations/db-run.ts#L1-L52)
- createControlClient builds a ControlStack from family, target, adapter, driver, and extensions, creates the family instance, and asserts framework-component compatibility before any connect. connect refuses a second connection until close and errors with CONFIG.DB_CONNECTION_REQUIRED when no connection was supplied. — [packages/1-framework/3-tooling/cli/src/control-api/client.ts#L76-L150](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/1-framework/3-tooling/cli/src/control-api/client.ts#L76-L150)
- On non-CI processes with telemetry enabled, resolveTelemetryHooks prints a first-run notice, then onSettled fires runTelemetry with the command path, CLI version, exit code, and cwd. The sender forks detached. The POST URL is TELEMETRY_ENDPOINT_PATH /events on https://cmpbfbsdp09hr3jf7pojjs5qs.ewr.prisma.build, overridable only by PRISMA_TELEMETRY_ENDPOINT. — [packages/1-framework/3-tooling/cli/src/orm/telemetry/reporting.ts#L71-L114](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/1-framework/3-tooling/cli/src/orm/telemetry/reporting.ts#L71-L114) [packages/1-framework/3-tooling/cli-telemetry/src/endpoint.ts#L1-L31](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/1-framework/3-tooling/cli-telemetry/src/endpoint.ts#L1-L31) [packages/1-framework/3-tooling/cli-telemetry/src/spawn.ts#L64-L78](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/1-framework/3-tooling/cli-telemetry/src/spawn.ts#L64-L78)
- loadContractFromTs bundles a user TypeScript contract with esbuild (platform node, target es2022) into a file under os.tmpdir named prisma-8-contract-*.mjs. The default import allowlist is @internal/*, @prisma/orm-*, and node:crypto. Imports from the entry that fail the allowlist become CONTRACT.SOURCE_IMPORT_DISALLOWED. Relative and absolute imports are not filtered. — [packages/1-framework/3-tooling/cli/src/load-ts-contract.ts#L39-L60](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/1-framework/3-tooling/cli/src/load-ts-contract.ts#L39-L60) [packages/1-framework/3-tooling/cli/src/load-ts-contract.ts#L130-L166](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/1-framework/3-tooling/cli/src/load-ts-contract.ts#L130-L166) [packages/1-framework/3-tooling/cli/src/load-ts-contract.ts#L184-L247](https://github.com/prisma/prisma/blob/dd867230cd8fe08d203b395999f20b4e717fe10b/packages/1-framework/3-tooling/cli/src/load-ts-contract.ts#L184-L247)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
