Skip to content

TML-3813: A Postgres migration.ts that imports the free createExtension fails with a clear error, and the rc.22 upgrade guide gives the fix - #30988

Merged
wmadden merged 3 commits into
mainfrom
tml-3813-free-create-extension
Nov 10, 2026
Merged

wmadden merged 3 commits into
mainfrom
tml-3813-free-create-extension

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue

Closes TML-3813.

At a glance

A PostgreSQL migration.ts written by the 8.0.0-rc.21 planner, or by hand, creates an extension with the free function:

import { createExtension, Migration, MigrationCLI } from '@prisma/orm-postgres/migration';

class M extends Migration {
  override get operations() {
    return [createExtension('btree_gist')];
  }
}

On 8.0.0-rc.22 and later, node migration.ts fails with only Cannot read properties of undefined (reading 'lowerToExecuteRequest'). No upgrade guide mentions it.

After this PR the import fails at once, with does not provide an export named 'createExtension', and the upgrade guides give the rewrite:

return [this.createExtension({ extension: 'btree_gist' })];

Why it broke

#30902 (released in 8.0.0-rc.22) changed the free function to async createExtension({ schema?, extension }, lowerer). Its checks are now query trees, and turning them into SQL needs the lowerer, which only the migration class has (through the Postgres control adapter). The function stayed in the public export, so a migration.ts could import it but never call it correctly. The rc.21 planner wrote createExtension("x") into every migration that created an extension, so planned migrations break too, not only hand-written ones.

The free dataTransform has the same problem: its fourth argument is the control adapter. The planner writes this.dataTransform(...), and nothing in the repository imports the free one.

What this PR changes

  1. packages/3-targets/postgres/1-target/src/exports/migration.ts no longer exports the free createExtension or dataTransform. The types DataTransformClosure and DataTransformOptions stay. The facade @prisma/orm-postgres/migration re-exports this module, so it changes too. A new test pins the full export list.
  2. The published 8.0.0-rc.21 → 8.0.0-rc.22 app and extension guides gain the missing entry create-extension-takes-options. It detects the free call and gives the rewrite. In rc.22 the method still requires schema, so the guide writes { schema: 'public', extension }.
  3. A pending fragment, upgrade-instructions/pending/migration-free-functions-not-exported/ (app and extension), records the export removal for the next release.
  4. skills/prisma-8/references/migrations.md lists createExtension, dropExtension and setExtensionSchema as methods, and no longer lists createExtension as a free helper.

prisma db migrate applies ops.json and never loads migration.ts, so applied migrations keep working. The rewrite runs the same SQL as rc.21 (CREATE EXTENSION IF NOT EXISTS "btree_gist"), so no migration needs to be planned again.

Testing

  • packages/3-targets/postgres/1-target/test/migrations/migration-exports.test.ts fails on main (the list contains createExtension and dataTransform) and passes here.
  • test/integration/test/upgrade-instructions/migration-free-functions-not-exported/detection.test.ts checks every new detection: a free call or import matches, this.createExtension(...), type-only imports and the MongoDB dataTransform do not.
  • Manual check against the built facade: importing createExtension or dataTransform from dist/migration.mjs fails with does not provide an export named ….
  • pnpm check:upgrade-coverage --mode pr and pnpm lint:ratchets pass.

Alternatives considered

  • Keep the old call shape working. The free function has no way to reach a control adapter, so it could only return the rc.21 form of the operation, with no checks and a different target. The operation id extension.x would then have two shapes. Rejected.
  • Only add the guide entry. The free function would stay exported but unusable, and the crash message would stay unclear. Rejected.

Agent: portia-43

Summary by CodeRabbit

  • Breaking Changes
    • Postgres migrations no longer expose the standalone createExtension and dataTransform functions. Use the corresponding migration class methods instead; migration-related types remain available.
  • Documentation
    • Updated upgrade guidance with steps for adapting affected migrations, including the required extension schema option.
    • Clarified that existing ops.json files do not need to be regenerated.

wmadden-electric and others added 3 commits November 10, 2026 17:42
Since rc.22 the free createExtension took a lowerer that a migration.ts
cannot supply, so the rc.21 call createExtension("x") crashed. Remove it
from the public export; migrations call this.createExtension. Add the
missing rc.21 to rc.22 recipe entry and a pending fragment for the
removal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The free dataTransform takes an internal fourth argument that a migration.ts cannot supply, the same problem as the free createExtension. Migrations call this.dataTransform, as the planner writes it. The types stay exported.

The upgrade guide entry for 8.0.0-rc.22 is renamed create-extension-takes-options, sits before contract-artifacts-restamp, and says re-running node migration.ts is not needed. The pending fragment is renamed migration-free-functions-not-exported and covers both functions.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
In 8.0.0-rc.22 the createExtension method requires schema; it became optional in 8.0.0-rc.23. The guides now write { schema: 'public', extension } and say to use the schema the extension is installed in.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric requested a review from a team as a code owner November 10, 2026 06:53
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Postgres migration module no longer exports the free functions createExtension and dataTransform. Migration references, upgrade instructions, and detection tests describe or check the corresponding migration-class methods and affected imports.

Changes: Postgres migration exports and upgrade guidance

Layer / File(s) Summary
Update migration exports and reference
packages/3-targets/postgres/1-target/src/exports/migration.ts, packages/3-targets/postgres/1-target/test/migrations/migration-exports.test.ts, skills/prisma-8/references/migrations.md
The migration module removes the createExtension and dataTransform free-function exports while retaining the data-transform types. The export test checks the expected names, and the reference updates the listed migration operations.
Detect and explain migration updates
upgrade-instructions/pending/migration-free-functions-not-exported/*, skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md, skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md, test/integration/test/upgrade-instructions/migration-free-functions-not-exported/detection.test.ts
Upgrade instructions describe detection and replacement guidance for affected migration calls and imports. Tests cover free-function calls and imports, exclude migration-class method calls, and distinguish the Postgres dataTransform import from type-only and MongoDB imports.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Suggested reviewers: aqrln

Merge Risk: Minimal · up to f44b1

No actionable issue remains in the reviewed changes; the PR is ready to merge after normal checks.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the createExtension export change and the rc.22 upgrade guidance, which are central parts of the pull request.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 3 files. (5 skipped: 5 unsupported.)

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: prisma/orm
  • Branch: main
  • File: .coderabbit.yml
  • Commit: 36ad1f2
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3d16992c-c32c-4f2c-a463-29655584f125
Commits

Reviewing files that changed from the base of the PR and between 36ad1f2 and f44b12c.

Files selected for processing: 8

  • packages/3-targets/postgres/1-target/src/exports/migration.ts
  • packages/3-targets/postgres/1-target/test/migrations/migration-exports.test.ts
  • skills/prisma-8/references/migrations.md
  • skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md
  • skills/prisma-8/upgrading/extension/upgrades/8.0.0-rc.21-to-8.0.0-rc.22/instructions.md
  • test/integration/test/upgrade-instructions/migration-free-functions-not-exported/detection.test.ts
  • upgrade-instructions/pending/migration-free-functions-not-exported/app/instructions.md
  • upgrade-instructions/pending/migration-free-functions-not-exported/extension/instructions.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

@prisma/orm-extension-arktype-json

npm i https://pkg.pr.new/@prisma/orm-extension-arktype-json@30988

@prisma/orm-extension-middleware-cache

npm i https://pkg.pr.new/@prisma/orm-extension-middleware-cache@30988

@prisma/orm-extension-paradedb

npm i https://pkg.pr.new/@prisma/orm-extension-paradedb@30988

@prisma/orm-extension-pgvector

npm i https://pkg.pr.new/@prisma/orm-extension-pgvector@30988

@prisma/orm-extension-postgis

npm i https://pkg.pr.new/@prisma/orm-extension-postgis@30988

@prisma/orm-extension-supabase

npm i https://pkg.pr.new/@prisma/orm-extension-supabase@30988

@prisma/orm-family-mongo

npm i https://pkg.pr.new/@prisma/orm-family-mongo@30988

@prisma/orm-family-sql

npm i https://pkg.pr.new/@prisma/orm-family-sql@30988

@prisma/orm-framework

npm i https://pkg.pr.new/@prisma/orm-framework@30988

@prisma/orm-mongo

npm i https://pkg.pr.new/@prisma/orm-mongo@30988

@prisma/orm-mysql

npm i https://pkg.pr.new/@prisma/orm-mysql@30988

@prisma/orm-postgres

npm i https://pkg.pr.new/@prisma/orm-postgres@30988

@prisma/orm-postgres-contrib

npm i https://pkg.pr.new/@prisma/orm-postgres-contrib@30988

@prisma/orm-sqlite

npm i https://pkg.pr.new/@prisma/orm-sqlite@30988

@prisma/orm-target-mongo

npm i https://pkg.pr.new/@prisma/orm-target-mongo@30988

@prisma/orm-target-mysql

npm i https://pkg.pr.new/@prisma/orm-target-mysql@30988

@prisma/orm-target-postgres

npm i https://pkg.pr.new/@prisma/orm-target-postgres@30988

@prisma/orm-target-sqlite

npm i https://pkg.pr.new/@prisma/orm-target-sqlite@30988

@prisma/orm-toolchain

npm i https://pkg.pr.new/@prisma/orm-toolchain@30988

commit: f44b12c

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
postgres / no-emit 283.97 KB (0%)
postgres / emit 248.15 KB (0%)
mongo / no-emit 229.88 KB (0%)
mongo / emit 183.99 KB (0%)
cf-worker / no-emit 346.16 KB (0%)
cf-worker / emit 306.13 KB (0%)

@wmadden
wmadden added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 623f5fd Nov 10, 2026
25 checks passed
@wmadden
wmadden deleted the tml-3813-free-create-extension branch November 10, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants