Skip to content

Fix Drizzle migration schema fallback#37

Merged
ponderingdemocritus merged 1 commit intomainfrom
ponderingdemocritus/db-schema
Feb 8, 2026
Merged

Fix Drizzle migration schema fallback#37
ponderingdemocritus merged 1 commit intomainfrom
ponderingdemocritus/db-schema

Conversation

@ponderingdemocritus
Copy link
Contributor

@ponderingdemocritus ponderingdemocritus commented Feb 8, 2026

This PR fixes facilitator server startup when migration metadata cannot be created in a separate schema.\n\nIt configures migrations to use the public schema and reuses the same migration runner in both startup and the standalone migration command.\n\nIt also adds a regression test for migration config behavior in facilitator-server.\n\nValidation: bun test (examples/facilitator-server), bun run build (packages/core, examples/facilitator-server).

Summary by CodeRabbit

  • Refactor
    • Centralized database migration configuration management, improving code organization and reducing internal dependencies.
  • Tests
    • Added unit tests to validate migration configuration behavior.

@coderabbitai
Copy link

coderabbitai bot commented Feb 8, 2026

📝 Walkthrough

Walkthrough

A helper function buildMigrationConfig is introduced to centralize database migration configuration, and migration logic in migrate.ts is refactored to delegate to a new runMigrations abstraction from db-migrate.ts. A unit test validates the new helper function's behavior.

Changes

Cohort / File(s) Summary
Migration Infrastructure
examples/facilitator-server/src/db-migrate.ts, examples/facilitator-server/src/migrate.ts
Added buildMigrationConfig helper to centralize migration config creation; refactored migrate.ts to call abstracted runMigrations(pool) instead of direct drizzle migrator calls, removing inline config and __dirname logic.
Testing
examples/facilitator-server/tests/db-migrate.test.ts
New unit test file validating buildMigrationConfig returns correct config with migrationsFolder and migrationsSchema set to "public".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~13 minutes

Possibly related PRs

No additional related PRs were found beyond the current change set in the provided search results.

Poem

🐰 A config built, abstracted clean,
Migration paths now centralized scene,
No more spreading logic around,
Neat and tidy, clearly bound! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 The title 'Fix Drizzle migration schema fallback' directly relates to the main change: configuring migrations to use the public schema as a fallback, which is the core objective of the PR.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ponderingdemocritus/db-schema

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
examples/facilitator-server/src/migrate.ts (1)

26-29: Consider wrapping in try/finally for pool cleanup on migration failure.

If runMigrations throws, pool.end() on line 29 is skipped. For a short-lived CLI script this is mostly cosmetic (the process exits and connections are reclaimed), but a try/finally would be slightly more robust and prevent potential connection-leak warnings from pg.

Proposed improvement
 console.log("Running migrations...");
-await runMigrations(pool);
-console.log("Migrations complete.");
-
-await pool.end();
+try {
+  await runMigrations(pool);
+  console.log("Migrations complete.");
+} finally {
+  await pool.end();
+}

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.

@ponderingdemocritus ponderingdemocritus merged commit 74aaa58 into main Feb 8, 2026
4 checks passed
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