Skip to content

feat: add database migration system with node-pg-migrate#31

Merged
SimonOyaneder merged 2 commits into
mainfrom
feat/db-migrations
Feb 26, 2026
Merged

feat: add database migration system with node-pg-migrate#31
SimonOyaneder merged 2 commits into
mainfrom
feat/db-migrations

Conversation

@SimonOyaneder

Copy link
Copy Markdown
Owner

Summary

  • Replace runtime ensureSchema() with proper SQL migrations using node-pg-migrate
  • Add baseline migration (0001_initial-schema.sql) extracted from existing schema creation logic
  • Update Railway deploy to run migrations before app start (npm run migrate && npm start)
  • Remove ensureSchema, buildSchemaSql, detectCurrentDimensions, and alterEmbeddingDimension from src/db/migrate.ts
  • Update integration tests to use node-pg-migrate runner instead of ensureSchema()

Test plan

  • npm run build compiles without errors
  • npm test — all 291 unit tests pass
  • npm run test:integration — integration tests use migration runner
  • Verify npm run migrate:create -- test generates a new migration file

🤖 Generated with Claude Code

Replace runtime schema creation (ensureSchema) with proper SQL migrations
using node-pg-migrate. Migrations run before app start on Railway deploys,
ensuring incremental schema changes are supported as features grow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@canon-review canon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Found 1 pattern deviations: 🟡 1 medium

Comment thread tests/integration/db-setup.ts Outdated
import { PostgreSqlContainer, StartedPostgreSqlContainer } from "@testcontainers/postgresql";
import { initPool, registerVectorTypes, closePool, resetPool } from "../../src/lib/db-client";
import { ensureSchema } from "../../src/db/migrate";
import runner from "node-pg-migrate";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Pattern Violation · medium · confidence: 83%

Default import of node-pg-migrate is inconsistent with the repo’s named-import style for external modules and can break depending on module interop behavior.

Existing pattern: External imports in the repo use named imports for module APIs (e.g., import { Probot } from "probot";) and avoid relying on default interop for CJS packages.
Reference: src/index.ts

Suggested change
import runner from "node-pg-migrate";
import { runner } from "node-pg-migrate";
await runner({
databaseUrl: connectionUri,
migrationsTable: "pgmigrations",
dir: path.resolve(__dirname, "../../migrations"),
direction: "up",
log: () => {},
});

Align with repo convention of using named imports for external modules.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@SimonOyaneder SimonOyaneder merged commit ef01dd2 into main Feb 26, 2026
2 checks passed
@SimonOyaneder SimonOyaneder deleted the feat/db-migrations branch February 26, 2026 20:16
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