Skip to content

feat(migrations): introduce model-aware operations, flat discovery, and colored CLI output#60

Merged
Einswilli merged 25 commits into
AllDotPy:masterfrom
Einswilli:new_design
Jun 3, 2026
Merged

feat(migrations): introduce model-aware operations, flat discovery, and colored CLI output#60
Einswilli merged 25 commits into
AllDotPy:masterfrom
Einswilli:new_design

Conversation

@Einswilli

Copy link
Copy Markdown
Contributor

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

  • New style.py utility module: Detects terminal color support and provides helpers (PREFIX, OK, FAIL, WARN, red, green, cyan...).
  • Updated CLI commands: makemigrations and migrate now output colored, nicely formatted messages.
  • Cleanup: Removed dead --plan handling and unused imports in the migrate command.

2. Model-Aware Migration Operations

  • Inject Model references: CreateTable, AddField, AlterField, and CreateIndex operations now optionally carry a reference to the Python Model class they originated from.
  • Auto-generated imports: The Autodetector collects these models and automatically writes from app.models import ModelA, ModelB at the top of generated migration files, making them fully runnable without manual edits.
  • Pretty-printed operations: to_python() methods now output multi-line, readable code rather than single-line dense strings.

3. Flat Discovery & Per-Alias Routing

  • Global file discovery: The migration runner now recursively finds all [0-9]*.py files under the migrations/ directory (ignoring __pycache__).
  • Per-alias filtering: Each file's operations are filtered at runtime via _operation_is_relevant() to only execute ops relevant to the current database alias (based on model._meta.database or the Router).
  • Qualified tracking keys: The ryx_migrations table now stores alias|stem keys (with backward compatibility for bare stems), allowing the same migration file to be marked as applied independently for different databases.

4. Interactive Fallback

  • The migrate command's interactive fallback (when no migration files are found) now uses the colored style module for a friendlier UX. It also gained --no-interactive support for CI environments to prevent hanging on input().

How to Test

  1. Run the CLI commands with a real model setup:
    ryx makemigrations --models myapp.models
    ryx migrate
  2. Verify the generated migration file is a runnable Python file (auto-imports work, no NameError).
  3. Test multi-DB by routing different models to different aliases and running ryx migrate twice (the second run should be a no-op).

Einswilli added 25 commits June 3, 2026 11:18
@Einswilli Einswilli merged commit e970e1e into AllDotPy:master Jun 3, 2026
3 of 4 checks passed
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