fix(api): add missing 0018 migration for onboarding & pages.kind#755
Conversation
PR #728 added the userOnboardingStatus table and the pages.kind column to the Drizzle TS schema but never produced a matching migration under server/api/drizzle/. CI runs only `bunx drizzle-kit migrate`, so the legacy SQL placed in db/migrations/005_*.sql was never applied to either dev or prod, leaving production with `relation "user_onboarding_status" does not exist` and `column "kind" of relation "pages" does not exist` (500 on GET /api/onboarding/status and POST /api/pages). This commit: - Adds server/api/drizzle/0018_add_onboarding_and_page_kind.sql with the pages.kind column + CHECK, the partial unique index used by welcomePageService.onConflictDoNothing, the user_onboarding_status table, the retry-scan partial index, and a backfill that marks existing users as setup-complete so they are not pushed back through the wizard. - Mirrors the partial unique index idx_pages_unique_welcome_per_owner in the TS schema for documentation parity. - Removes the legacy db/migrations/ directory entirely; CI never touched it and leaving it around invites the same regression. README is updated to point at server/api/drizzle/ as the single source of truth. Re-fix-prevention: - New CI job drizzle-migration-check (PR-only) runs scripts/check-drizzle-migrations.mjs, which fails when a PR modifies any server/api/src/schema/**/*.ts file without adding a matching server/api/drizzle/NNNN_*.sql and updating _journal.json. PRs that truly do not need a DB migration can opt out with [skip drizzle-check]. - AGENTS.md / CLAUDE.md document the schema/migration pairing rule and the develop->dev / main->prod auto-apply pipeline. Made-with: Cursor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a CI job and Node CLI to enforce that TypeScript Drizzle schema edits are paired with new SQL migrations and journal updates; moves documented migration path to Changes
Sequence Diagram(s)sequenceDiagram
participant GH as GitHub Actions (ci.yml)
participant Repo as Git Repo
participant Script as check-drizzle-migrations.mjs
participant PR as Pull Request (title/body/commits)
GH->>Repo: checkout (fetch-depth:0)
GH->>PR: read PR_TITLE, PR_BODY, PR base/branch
GH->>Script: run node scripts/check-drizzle-migrations.mjs with env
Script->>Repo: git diff (base..HEAD) -> changed/added paths
Script->>Script: detect schema .ts changes under server/api/src/schema/
alt schema changes found
Script->>Repo: check for added server/api/drizzle/*.sql (excluding /meta/)
Script->>Repo: check meta/_journal.json modified
alt migrations & journal present
Script->>GH: exit 0 (OK)
else skip marker present in commits/title/body
Script->>GH: exit 0 (skipping)
else
Script->>GH: exit 1 (FAIL with remediation message)
end
else no schema changes
Script->>GH: exit 0 (no-op)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Code Review
This pull request formalizes the database migration workflow by consolidating migrations into server/api/drizzle/ and introducing a validation script, scripts/check-drizzle-migrations.mjs, to ensure TypeScript schema changes are always accompanied by SQL migrations. Documentation in AGENTS.md, CLAUDE.md, and README.md has been updated to reflect these requirements. Feedback was provided regarding the validation script's potential to silently skip checks in CI environments due to shallow clones, which could lead to undetected schema inconsistencies.
| if (!ensureBaseExists(base)) { | ||
| console.log( | ||
| `[check-drizzle-migrations] base ref "${base}" not found; skipping check (most likely running outside PR context).`, | ||
| ); | ||
| return; | ||
| } |
There was a problem hiding this comment.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 240d18d82c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| * @returns {string[]} | ||
| */ | ||
| function changedPaths(base) { | ||
| const out = git(["diff", "--name-only", "--diff-filter=AMR", `${base}...HEAD`]); |
There was a problem hiding this comment.
Detect deleted schema files in migration check
Use a diff filter that includes deletions when collecting schema changes. The current git diff --name-only --diff-filter=AMR ignores D, so removing a file under server/api/src/schema/** (for example, dropping a table schema module) will not trigger this guard and CI can pass without adding a migration/journal update, reintroducing the exact schema-drift failure this check is meant to prevent.
Useful? React with 👍 / 👎.
Tighten the Drizzle migration consistency checker by detecting deleted schema files, honoring the documented types/ exclusion, failing fast in CI when the diff base is unavailable, and aligning JSDoc with the required SQL-plus-journal policy. Made-with: Cursor
概要
#728 でマージされた welcome page 関連スキーマ変更(
user_onboarding_statusテーブルとpages.kindカラム)に対応する Drizzle マイグレーションが生成されていなかったため、本番および開発 DB が TS スキーマに追いつかず、/api/onboarding/statusと/api/pagesが 500 を返していた。Railway 本番ログ:
```
relation "user_onboarding_status" does not exist (42P01)
column "kind" of relation "pages" does not exist (42703)
```
CI (
.github/workflows/deploy-{dev,prod}.yml) はbunx drizzle-kit migrateのみを実行するため、PR #728 で追加されたdb/migrations/005_add_onboarding_and_page_kind.sql(drizzle-kit が見ないパス)は永久に適用されない状態だった。変更点
不足マイグレーションの追加(即時の 500 解消)
再発防止
変更の種類
環境別の自動適用について
ご質問の「develop にマージしたら development 環境、main にマージしたら production 環境にマイグレーションを適用したい」は、すでに `deploy-{dev,prod}.yml` の `migrate` ジョブが実装済みです。今回 #728 で適用されなかったのは、TS スキーマだけ変更して SQL を別ディレクトリに置いたために `drizzle-kit migrate` が「適用すべきものなし」と判断したためで、本 PR の `drizzle-migration-check` ジョブで再発を防ぎます。
テスト方法
マイグレーション検証
CI ガード検証
チェックリスト
関連
Made with Cursor
Summary by CodeRabbit
New Features
Chores
Documentation