Skip to content

Comments

Add database migration system#345

Merged
rsslldnphy merged 7 commits intomainfrom
migrations
Jan 31, 2026
Merged

Add database migration system#345
rsslldnphy merged 7 commits intomainfrom
migrations

Conversation

@rsslldnphy
Copy link
Member

@rsslldnphy rsslldnphy commented Jan 27, 2026

Summary

  • Adds a complete migration system that diffs TypeScript schema config against the live database, generates SQL migration files, and runs them with safety checks
  • Schema diffing engine compares config state vs database state via a normalised SchemaSnapshot intermediate representation
  • Safety classification (inspired by strong_migrations gem) warns on unsafe operations like dropping tables/columns or unsafe type casts
  • Migration runner uses PostgreSQL advisory locks to prevent concurrent migration runs across app instances
  • Tracks applied migrations in _orm_migrations table with SHA-256 checksum verification
  • Supports non-transactional migrations (e.g. CREATE INDEX CONCURRENTLY) via -- orm:no-transaction directive
  • CLI: orm generate migration --name <desc>, orm db migrate, orm db migrate status
  • Programmatic API: migrate.generate(), migrate.run(), migrate.status() for app-startup usage
  • Enhances getForeignKeys to return onUpdate/onDelete actions
  • Enhances getUniqueConstraints to return structured column data and nullsNotDistinct

Test plan

  • Existing orm-migrate tests pass (67/67)
  • Existing orm-cli tests pass (100/100)
  • Both packages build cleanly with no type errors
  • Unit tests for new migration modules (diffSnapshots, operationToSql, checkSafety, safeCasts, files, configToSnapshot, pulledToSnapshot)
  • Integration tests with database (generate, run, status, locking, tracking)

🤖 Generated with Claude Code

@github-actions
Copy link
Contributor

github-actions bot commented Jan 31, 2026

Coverage Report

  • orm-cli: 96.85%
  • orm-migrate: 94.02%
  • orm: 98.47%
  • sql: 96.93%
  • toolbox: 100%

@rsslldnphy rsslldnphy marked this pull request as ready for review January 31, 2026 10:22
Introduces a complete migration workflow:
- Schema diffing engine that compares TypeScript config against the live database
- SQL migration file generation with timestamped naming
- Safety checks inspired by strong_migrations (warns on drops, unsafe type casts, etc.)
- Migration runner with PostgreSQL advisory locking for concurrent safety
- Migration tracking table (_orm_migrations) with checksum verification
- Support for non-transactional migrations via -- orm:no-transaction directive
- CLI commands: orm generate migration, orm db migrate, orm db migrate status
- Programmatic API: migrate.generate(), migrate.run(), migrate.status()

Also enhances getForeignKeys to return onUpdate/onDelete actions and
getUniqueConstraints to return structured column data and nullsNotDistinct.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@rsslldnphy rsslldnphy merged commit e492d5a into main Jan 31, 2026
14 checks passed
@rsslldnphy rsslldnphy deleted the migrations branch January 31, 2026 13:13
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