Skip to content

Conversation

@channelcat
Copy link
Contributor

Finally, I can make smaller PRs 😂

This swaps migration manager to using generators and yielding migrations for create/apply. This allows people to customize the output and show results as they occur when implementing the manager in their own tooling. I also moved the responsibility of printing status to the CLI for these functions.

@henadzit henadzit requested a review from Copilot July 5, 2025 18:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Swaps the migration manager’s create_migrations and apply_migrations methods to use async generators, lets the CLI handle printing status, and updates tests to iterate over those generators.

  • Change create_migrations and apply_migrations to return AsyncGenerator and yield migrations
  • Move print statements from manager into CLI commands and wrap operations in try/except
  • Update end-to-end tests to consume async generators with async for

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tortoise_pathway/migration_manager.py Refactored methods to async generators, updated return types and docstrings
tortoise_pathway/cli.py Updated CLI to iterate over migrations, print results, and handle errors
tests/e2e/test_no_migrations_app.py Changed await calls to async for loops
tests/e2e/test_model_changes_app.py Changed await calls to async for loops
tests/e2e/test_applied_migrations_app.py Changed await calls to async for loops
Comments suppressed due to low confidence (1)

tortoise_pathway/migration_manager.py:113

  • The docstring mentions a ValueError for empty migrations with no app specified, but the code never raises this error. Either remove this entry or implement the check as documented.
            ValueError: If no app is specified for an empty migration

else:
# Create an empty migration
migrations = await manager.create_migrations(name, app=app, auto=False)
# Generate automatic migration based on model changes?
Copy link

Copilot AI Jul 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The comment ends with a question mark and may be unclear. Consider rephrasing to a descriptive statement (e.g., "Determine whether to auto-generate migrations").

Suggested change
# Generate automatic migration based on model changes?
# Determine whether to generate automatic migrations based on model changes.

Copilot uses AI. Check for mistakes.
Copy link
Owner

@henadzit henadzit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I left a single message about exception reporting.

else:
print("No migrations were applied.")
except Exception as e:
print(f"Error applying migrations: {e}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will provide very limited information about the exception to the user. At this stage, it would be beneficial to have the whole stack trace which users can report, so, I think we either need to improve the exception reporting or not catch the exception at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if reverted:
print(f"Successfully reverted migration: {reverted.display_name()}")
else:
print("No migration was reverted.")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Owner

@henadzit henadzit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@henadzit henadzit merged commit 19bb026 into henadzit:main Jul 10, 2025
1 check 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.

2 participants