prisma dev applies migrations but never moves the db ref, so the second prisma migration plan fails with MIGRATION.PLAN_ORIGIN_UNKNOWN
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- node.js, postgresql, typescript
調査の方向性
Start with docs/guides/building-an-app.md and the postgres() workflow, then trace how prisma dev applies migrations and records the development database's contract ref. Compare that behavior with prisma db migrate, which moves the ref in an ORM-only app. Done when the documented contract emit → migration plan → prisma dev loop can plan a second schema change from the database's current contract.
索引モデルが issue の本文から書いたものです。
説明
Reproduced on 2026-11-30 on macOS, Node.js 24.13.0, Bun 1.3.13, with Composer 0.40.0, prisma 8.0.0-rc.36 and @prisma/orm-postgres 8.0.0-rc.25.
The app
Versions installed (package.json):
{
"type": "module",
"dependencies": {
"@prisma/composer": "0.40.0",
"@prisma/composer-prisma-cloud": "0.40.0",
"@prisma/orm-postgres": "8.0.0-rc.25",
"arktype": "^2.2.9",
"pg": "8.22.0",
"prisma": "8.0.0-rc.36"
},
"devDependencies": {
"@types/pg": "8.20.0",
"@types/bun": "1.3.13",
"typescript": "6.0.3"
}
}
The app
contract.prisma:
// use prisma-8
model Quote {
id Int @id @default(autoincrement())
text String
}
prisma.config.ts:
import { defineConfig as composer } from '@prisma/composer/config';
import { nodeBuild } from '@prisma/composer/node/control';
import { prismaCloud, prismaState } from '@prisma/composer-prisma-cloud/control';
import { defineConfig as orm } from '@prisma/orm-postgres/config';
import { definePrismaConfig } from 'prisma/config';
export default definePrismaConfig({
composer: composer({
entry: './module.ts',
extensions: [prismaCloud(), nodeBuild()],
state: prismaState(),
}),
orm: orm({
contract: './contract.prisma',
}),
});
src/data.ts:
import { dataContract } from '@prisma/composer-prisma-cloud/orm';
import type { Contract } from '../contract.d.ts';
import contractJson from '../contract.json' with { type: 'json' };
export const quotesData = dataContract<Contract>(contractJson);
src/service.ts:
import { rawHttpContract } from '@prisma/composer/http';
import node from '@prisma/composer/node';
import { compute } from '@prisma/composer-prisma-cloud';
import { postgres } from '@prisma/composer-prisma-cloud/orm';
import { quotesData } from './data.ts';
export default compute({
name: 'quotes',
deps: { db: postgres(quotesData) },
build: node({ module: import.meta.url, entry: '../dist/server.mjs' }),
expose: { http: rawHttpContract },
});
module.ts:
import { appRoot } from '@prisma/composer';
import { publicUrl } from '@prisma/composer-prisma-cloud';
import { postgres } from '@prisma/composer-prisma-cloud/orm';
import { quotesData } from './src/data.ts';
import quotesService from './src/service.ts';
export default appRoot('quotes-app', ({ provision }) => {
const db = provision(
postgres({ name: 'database', contract: quotesData, config: './prisma.config.ts' }),
);
const quotes = provision(quotesService, { deps: { db } });
provision(publicUrl({ id: 'site', url: publicUrl.prismaBuild(), target: quotes.http }));
});
src/server.ts is a Bun.serve fetch handler that reads and writes db.client.orm.public.Quote (the file is in the scratch folder; any server that listens on service.port() reproduces both defects). It is built with bun build src/server.ts --target=bun --outfile dist/server.mjs.
The first repro ran with an earlier module.ts without the publicUrl() line and a service.ts without expose; the defects do not depend on either.
Composer's guide (docs/guides/building-an-app.md at v0.40.0, the postgres() workflow steps 1 to 4) and the skill describe each schema change as prisma contract emit then prisma migration plan --name <slug>. The ORM's db ref records which contract the development database is at and moves when the development database is migrated. prisma dev migrates the development database but does not move the ref, so the loop works for the first migration only.
Steps:
npx prisma contract emit
npx prisma migration plan --name init
bun build src/server.ts --target=bun --outfile dist/server.mjs
npx prisma dev --detach
Output of migration plan --name init (succeeds):
app space: migrations/app/20261130T0434_init
ℹ DDL preview
CREATE SCHEMA IF NOT EXISTS "public";
CREATE TABLE "public"."Quote" (
"id" SERIAL NOT NULL,
"text" text NOT NULL,
PRIMARY KEY ("id")
);
→ Review migrations/app/20261130T0434_init
→ Apply the migration: prisma db migrate
prisma dev --detach succeeds, applying the migration (✔ created quotes-app.database.migration, then dev: ready). migrations/app/refs/db.json does not exist afterwards.
Then change the schema: add author String? to Quote in contract.prisma, and run:
npx prisma contract emit
npx prisma migration plan --name add-author
Output of the second migration plan (fails):
✘ [MIGRATION.PLAN_ORIGIN_UNKNOWN] Cannot determine the plan origin: migrations exist but no origin is named
why: Migrations exist on disk, but there is no `db` ref and no --from was given, so the plan origin would silently fall back to an empty database and the resulting migration would recreate everything the existing migrations already create.
→ Point the db ref at the contract your database is at with `prisma migration ref set db <contract>`, replacing <contract> with one of `6cffa1794b3ecbb1e2f75485fc7326de48d6f0555308d18046ba1c495f529a6a`
→ Plan from an explicit origin with `prisma migration plan --from 6cffa1794b3ecbb1e2f75485fc7326de48d6f0555308d18046ba1c495f529a6a`. No `db` ref and no --from say where the plan starts.
→ Plan from an empty database deliberately: prisma migration plan --from @empty
docs: https://docs.prisma.io/docs/orm/v8/reference/error-reference/MIGRATION.PLAN_ORIGIN_UNKNOWN
Expected: the plan starts from the contract the prisma dev database is at (6cffa179…), as it does after prisma db migrate in an ORM-only app.
A workaround exists, but the guide does not describe it: npx prisma migration plan --name add-author --from 20261130T0434_init succeeds (ALTER TABLE "public"."Quote" ADD COLUMN "author" text;), and the next prisma dev --detach applies it (✔ updated quotes-app.database.migration, dev: ready), keeping the existing rows.
Found while writing the Composer database docs on prisma.io. The docs describe the bare migration plan loop from Composer's guide and do not work around this.
- 主要言語
- TypeScript
- スター
- 6
- フォーク
- 2
- 平均マージ
- 1日 2時間
- マージ済み PR(30日)
- 33
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
prisma/composer のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 67/100
メンテナーはふだん 1 日以内に返信
prisma/composer の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
zabuton-app/meguri#875 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
iruzen-dono/workless#117 ·
メンテナーはふだん 1 日以内に返信
-
area:api area:web wave wave:trivial
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
vetro-protocol/vetro-monorepo#1321 ·
メンテナーはふだん 1 日以内に返信