Skip to content

fix: 移行スクリプトのパス解決バグを修正#247

Merged
coji merged 1 commit intomainfrom
fix/migrate-integrations-path
Mar 24, 2026
Merged

fix: 移行スクリプトのパス解決バグを修正#247
coji merged 1 commit intomainfrom
fix/migrate-integrations-path

Conversation

@coji
Copy link
Owner

@coji coji commented Mar 24, 2026

Summary

  • path.join で絶対パスが二重結合される問題を修正(/upflow/upflow/data/data.db
  • DB が見つからない場合は skip ではなく throw でプロセスを停止

背景

#245 のデプロイ時に、DATABASE_URL=file:/upflow/data/data.db の pathname を path.join(process.cwd(), ...) で結合したため、パスが /upflow/upflow/data/data.db になり DB が見つからなかった。スクリプトは「skip」として正常終了し、データがコピーされないまま tenant の integrations テーブルが削除された。

Test plan

  • pnpm validate 全パス
  • 本番データは Web UI から手動復旧済み

🤖 Generated with Claude Code

Summary by CodeRabbit

リリースノート

  • 新機能
    • 共有データベースのパス解決ロジックを共通化するヘルパーを導入しました。これにより各処理から共有パス解決が利用可能になります。
  • バグ修正
    • データベース移行時に共有ファイルが見つからない場合、詳細なエラーメッセージが表示され処理が停止するようになりました(パスと現在のデータベース設定を含む)。

@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2026

Warning

Rate limit exceeded

@coji has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 8 minutes and 35 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d0ec436b-bf7a-4115-b4e1-8fef4f3ed51f

📥 Commits

Reviewing files that changed from the base of the PR and between 2b462e8 and 92e259a.

📒 Files selected for processing (24)
  • .env.example
  • .github/workflows/deploy.yml
  • .gitignore
  • Dockerfile
  • README.md
  • app/libs/auth.server.test.ts
  • app/libs/dotenv.server.ts
  • app/libs/github-app-state.server.test.ts
  • app/libs/timezone.server.test.ts
  • app/routes/$orgSlug/settings/github-users._index/mutations.server.test.ts
  • app/routes/$orgSlug/settings/repositories._index/mutations.server.test.ts
  • app/routes/$orgSlug/settings/repositories/$repository/settings/+functions/mutations.server.test.ts
  • app/routes/$orgSlug/settings/teams._index/mutations.server.test.ts
  • app/routes/$orgSlug/workload/$login/+functions/queries.server.test.ts
  • app/services/db.server.ts
  • app/services/github-webhook.server.test.ts
  • app/services/tenant-db.server.test.ts
  • app/services/tenant-db.server.ts
  • batch/db/mutations.test.ts
  • batch/github/store.test.ts
  • db/apply-tenant-migrations.ts
  • db/data-dir.ts
  • db/migrate-integrations-to-shared.ts
  • start.sh
📝 Walkthrough

Walkthrough

共通の共有DBパス解決ロジックを resolveSharedDbPath() に抽出し、呼び出し側はそれを利用するように変更。共有DB未検出時の挙動をログから例外スローへ変更し、スクリプト内の環境依存パス正規化を削除した。

Changes

Cohort / File(s) Summary
共有DBパス解決の抽出・利用
app/services/db.server.ts, app/services/tenant-db.server.ts
resolveSharedDbPath()app/services/db.server.ts に追加。getSharedDbState()getTenantDbPath() がこの新関数を利用するように切り替え、各所から DATABASE_URL の直接読み取りや環境依存のパス正規化を削除。
マイグレーションスクリプトのエラーハンドリング変更
db/migrate-integrations-to-shared.ts
共有DBパス解決を外部関数に委譲。共有DBが存在しない場合、情報ログでの早期リターンから Error を投げる実装へ変更。旧来のURL解析/NODE_ENV依存の正規化ロジックを除去。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 小さなウサギが走る、コードの野を越え
パスを見つけて、ひと跳びでつなぐよ
エラーは声高く、場所を示すだけ
シンプルな道で、みんな戻れる
ぴょん、と修正、また一歩前へ ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PRタイトルは日本語で「移行スクリプトのパス解決バグを修正」であり、実際の変更内容である「resolveSharedDbPath()」の導入によるパス解決ロジックの一元化と、DB見つからない場合のエラーハンドリング改善に関連している。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/migrate-integrations-path

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@db/migrate-integrations-to-shared.ts`:
- Around line 13-18: The path normalization currently checks
pathname.startsWith('/') which misclassifies relative file: URLs like
"file:./data/db" because new URL() normalizes them; update sharedDbFilePath to
inspect the original DATABASE_URL string instead: get const urlStr =
process.env.DATABASE_URL ?? 'file:./data/data.db', then if urlStr
startsWith('file:') and does NOT startWith('file:///') treat it as a relative
file URL and resolve to an absolute path via join(process.cwd(), new
URL(urlStr).pathname); otherwise parse with new URL(urlStr) and, for absolute
file URLs (file:///...) return the URL.pathname as before. This change targets
the function sharedDbFilePath and the DATABASE_URL handling logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 67211e4f-8418-47f3-a856-540a3788a326

📥 Commits

Reviewing files that changed from the base of the PR and between c9c4e8e and 94764dd.

📒 Files selected for processing (1)
  • db/migrate-integrations-to-shared.ts

@coji coji force-pushed the fix/migrate-integrations-path branch 7 times, most recently from a6c0bd0 to ea421b2 Compare March 24, 2026 11:25
DATABASE_URL をパースして NODE_ENV で prefix を分岐する自前ロジックを完全廃止。
Dockerfile で既に定義されていた UPFLOW_DATA_DIR を正本にする。

- db/data-dir.ts: resolveDataDir() を軽量モジュールとして抽出
- db.server.ts: resolveDataDir() を re-export、path.join(dataDir, 'data.db')
- tenant-db.server.ts: resolveDataDir() から tenant DB パスを組み立て
- apply-tenant-migrations.ts / migrate-integrations-to-shared.ts: resolveDataDir() を使用
- start.sh: UPFLOW_DATA_DIR から DB URL を組み立て
- Dockerfile: DATABASE_URL を削除(不要になった)
- dotenv.server.ts: DATABASE_URL を必須から削除、UPFLOW_DATA_DIR を追加
- .env.example / README.md: DATABASE_URL → UPFLOW_DATA_DIR に更新
- テスト: DATABASE_URL / NODE_ENV=production の stub を全削除、UPFLOW_DATA_DIR のみに
- DB 未発見時は throw でプロセス停止

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coji coji force-pushed the fix/migrate-integrations-path branch from ea421b2 to 92e259a Compare March 24, 2026 11:29
@coji coji merged commit edd1c45 into main Mar 24, 2026
6 checks passed
@coji coji deleted the fix/migrate-integrations-path branch March 24, 2026 11:34
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.

1 participant