feat: add database migration system with node-pg-migrate#31
Merged
Conversation
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>
| 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"; |
There was a problem hiding this comment.
🟡 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ensureSchema()with proper SQL migrations usingnode-pg-migrate0001_initial-schema.sql) extracted from existing schema creation logicnpm run migrate && npm start)ensureSchema,buildSchemaSql,detectCurrentDimensions, andalterEmbeddingDimensionfromsrc/db/migrate.tsnode-pg-migraterunner instead ofensureSchema()Test plan
npm run buildcompiles without errorsnpm test— all 291 unit tests passnpm run test:integration— integration tests use migration runnernpm run migrate:create -- testgenerates a new migration file🤖 Generated with Claude Code