Add migration directory validation utility and CLI command#2
Merged
Conversation
Adds a CLI command that validates the opinionated shape of a Kysely migrations directory: - directory is non-empty - every file is prefixed with a 5-digit migration number - every module exports an up() and down() function - no duplicate migration numbers (branch collisions) Exits 0 when valid, non-zero otherwise. Duplicate numbers are errors by default but can be downgraded to warnings via --duplicates-as-warnings. https://claude.ai/code/session_01V7f97zUsEZoVrpfNj1S5KQ
Add a pull_request trigger so lint, unit, E2E, and CLI test jobs run on PRs. Guard the three publish jobs (GitHub Packages, NPMJS, GHCR Docker image) with 'if: github.event_name == "push"' so publishing only happens on push to main. https://claude.ai/code/session_01V7f97zUsEZoVrpfNj1S5KQ
Document the opinionated migration file format (5-digit prefix, up()/down() exports, unique numbers) with examples using both the Kysely<any> query builder and the sql template tag from @/sql, plus how to validate, build, and run migrations via the dbh CLI. https://claude.ai/code/session_01V7f97zUsEZoVrpfNj1S5KQ
Migration files must always import sql from @/sql; the build-db-migrations step rewrites that literal specifier to the built sql.js, so external consumers must configure the @/sql alias locally rather than importing from @schemavaults/dbh/sql. https://claude.ai/code/session_01V7f97zUsEZoVrpfNj1S5KQ
Reframe the database-migrations skill for consumers of the @schemavaults/dbh package: use bunx/npx @schemavaults/dbh for all CLI commands, add a one-time consumer setup section (local sql.ts module + @/sql tsconfig path alias), and remove in-repo references (bun run cli, ./src/tests/example-migrations). https://claude.ai/code/session_01V7f97zUsEZoVrpfNj1S5KQ
Most PostgreSQL drivers target Node.js rather than Bun, so apply/run migrations with npx; validating and building (Bun's bundler) use bunx. https://claude.ai/code/session_01V7f97zUsEZoVrpfNj1S5KQ
Minor bump for the new validate-migration-directory CLI command. https://claude.ai/code/session_01V7f97zUsEZoVrpfNj1S5KQ
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
Adds a new
validateMigrationDirectoryutility function and corresponding CLI command to validate the structure and integrity of Kysely migrations directories. This helps catch common issues like missing 5-digit prefixes, duplicate migration numbers (branch collisions), and missingup()/down()exports.Key Changes
New utility module (
src/utils/validateMigrationDirectory.ts):00000-my-migration.ts)up()anddown()functions.d.tsdeclaration files and dotfilesduplicatesAsWarningsflag to downgrade duplicate number issues from errors to warningsNew CLI command (
validate-migration-directory/validate):--duplicates-as-warningsflagComprehensive test suite (
src/tests/ValidateMigrationDirectory.test.ts):duplicatesAsWarningsoptionup()/down()function exportsDocumentation (README.md):
validate-migration-directorycommandImplementation Details
import()withpathToFileURLto load and validate migration modules at runtime/^(\d{5})(?:\D|$)/) ensures exactly 5-digit prefixeshttps://claude.ai/code/session_01V7f97zUsEZoVrpfNj1S5KQ