feat(migrations): introduce model-aware operations, flat discovery, and colored CLI output#60
Merged
Merged
Conversation
…upport in Autodetector
… in migrate command
… and interactive CLI fallback
…ng, and styled CLI output
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.
PR Description
Overview
This PR significantly upgrades the Ryx migration engine and CLI. The key goal is to make migrations fully multi-database aware, self-documenting in their generated code, and provide a much better developer experience with colored terminal output in the CLI.
We've also refactored the migration runner to use a flat-discovery strategy, allowing migration files to be shared and selectively applied based on the database alias.
Key Changes
1. Colored & Styled CLI
style.pyutility module: Detects terminal color support and provides helpers (PREFIX,OK,FAIL,WARN,red,green,cyan...).makemigrationsandmigratenow output colored, nicely formatted messages.--planhandling and unused imports in themigratecommand.2. Model-Aware Migration Operations
CreateTable,AddField,AlterField, andCreateIndexoperations now optionally carry a reference to the PythonModelclass they originated from.Autodetectorcollects these models and automatically writesfrom app.models import ModelA, ModelBat the top of generated migration files, making them fully runnable without manual edits.to_python()methods now output multi-line, readable code rather than single-line dense strings.3. Flat Discovery & Per-Alias Routing
[0-9]*.pyfiles under themigrations/directory (ignoring__pycache__)._operation_is_relevant()to only execute ops relevant to the current database alias (based onmodel._meta.databaseor theRouter).ryx_migrationstable now storesalias|stemkeys (with backward compatibility for bare stems), allowing the same migration file to be marked as applied independently for different databases.4. Interactive Fallback
migratecommand's interactive fallback (when no migration files are found) now uses the coloredstylemodule for a friendlier UX. It also gained--no-interactivesupport for CI environments to prevent hanging oninput().How to Test
NameError).ryx migratetwice (the second run should be a no-op).