[Regression on closed #570 / #318] Still no initial-schema migration — migration:run on a fresh database fails on the first ALTER TABLE

オープン
#736 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
postgresql, typescript
領域
backend, database

調査の方向性

Read src/database/data-source.ts:22 and inspect all migrations in src/database/migrations/, especially the earliest migration at 1784272650000-EscrowFkIntegrityAndSponsorId.ts:32. Reproduce the failure with npm run migration:run against an empty PostgreSQL database, then establish a baseline that creates the current schema and works with existing deployments. Done means migrations succeed from an empty database and a required CI job verifies that path.

索引モデルが issue の本文から書いたものです。

説明

bug

Location — src/database/migrations/ (the whole directory), entry point src/database/data-source.ts:22. The earliest migration is 1784272650000-EscrowFkIntegrityAndSponsorId.ts:32.

Problem — The missing initial-schema migration closed as #318 and re-filed and closed as #570 is still missing on the default branch. Of the 15 migration files, exactly one contains a CREATE TABLE (1784304511000-CreateIdempotencyKeys.ts, for idempotency_keys). Every other migration is an ALTER TABLE / CREATE INDEX / ADD CONSTRAINT against tables that no migration ever creates: escrows, bounties, payments, issues, milestones, maintenance_pools, repositories, teams, team_member_splits, reputation_snapshots, users, github_accounts, webhook_events.

The first migration to run begins with:

await queryRunner.query(
  `ALTER TABLE "escrows" ADD COLUMN IF NOT EXISTS "sponsorId" varchar`,
);

Against an empty database this aborts with ERROR: relation "escrows" does not exist. (ADD COLUMN IF NOT EXISTS guards the column, not the table.) The schema therefore still only ever comes into existence through synchronize, which data-source.ts:25 correctly sets to false for the CLI — so the migration path and the only working schema-creation path are disjoint.

Why it matters — There is no way to stand up this application from the repository. A new contributor, a fresh CI database, a staging rebuild, or a production deploy all fail at the first migration. The practical workaround is to boot the app once with synchronize: true and then run migrations, which means the deployed schema is whatever the entity decorators happened to produce at that moment, with no reviewable record — the exact situation migrations were introduced (#14, #27) to eliminate. It also makes entity/migration drift undetectable: there is no baseline to diff against.

Reproduction / failure path

  1. createdb mergefi_fresh
  2. DATABASE_URL=postgresql://postgres:postgres@localhost:5432/mergefi_fresh npm run migration:run
  3. Fails immediately: QueryFailedError: relation "escrows" does not exist.

Suggested fix

  • Generate a baseline migration that creates the full current schema and number it before 1784272650000: boot a scratch database with synchronize: true against the current entities list, then run npm run migration:generate -- src/database/migrations/InitialSchema from an empty database and renumber the output to a timestamp lower than 1784272650000.
  • Make it idempotent for already-deployed environments (CREATE TABLE IF NOT EXISTS / CREATE TYPE ... IF NOT EXISTS guards), or document that existing databases must have the row inserted into migrations manually so the baseline is recorded as applied without re-running.
  • Add the CI step that #320/#572 asked for and wire it to a genuinely empty Postgres service container: migration:run on a fresh database must be a required job. Without it this will regress a fourth time — a migration suite that is never run from zero cannot be known to work.
主要言語
TypeScript
スター
2
フォーク
90
平均マージ
31分
マージ済み PR(30日)
20

環境構築

  • Dockerfile または Docker Compose ファイルあり
  • プルリクエストのテンプレートなし
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

MergeFi/backend のほかの issue

MergeFi/backend の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。