-
-
Notifications
You must be signed in to change notification settings - Fork 28
Add schema.update method for intelligent schema migration #593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: FCO <99834+FCO@users.noreply.github.com>
Co-authored-by: FCO <99834+FCO@users.noreply.github.com>
|
@copilot instead of implementing that, I think it's better to add the method |
I understand. Instead of the |
- Add update method to Red::Schema that compares model definitions with database state - Uses existing diff-from-db and diff-to-ast infrastructure for changes - Handles missing tables, column differences, and relationship updates - Includes comprehensive tests for various update scenarios - Method is idempotent and preserves existing data - Supports method chaining like other schema methods This addresses FCO's feedback to provide a more sophisticated schema update mechanism instead of simple :if-not-exists flag. Co-authored-by: FCO <99834+FCO@users.noreply.github.com>
- Add comprehensive documentation to the update method - Create example showing real-world usage patterns - Document that method is idempotent and preserves data - Show method chaining capabilities Co-authored-by: FCO <99834+FCO@users.noreply.github.com>
This PR adds a new
updatemethod toschema(...)objects that intelligently compares the current schema definition with the database state and applies necessary changes to make them match.Problem
Previously, there was no way to automatically update database schemas when model definitions changed. Users had to manually manage schema migrations or recreate tables entirely:
Solution
Added a new
updatemethod toRed::Schemathat provides intelligent schema migration:The method can also be chained like other schema methods:
Implementation
The implementation leverages Red's existing schema comparison infrastructure:
Red::Schema.updatemethod that compares model definitions with database state usingdiff-from-dbdiff-to-astinfrastructure to convert differences into executable AST nodesThe solution reuses Red's robust schema reading and migration mechanisms, ensuring consistency with existing patterns.
Key Features
Testing
Added comprehensive tests covering:
All existing tests continue to pass, ensuring no breaking changes.
Usage Example
Fixes #482.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.