Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions piccolo/apps/migrations/commands/forwards.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ async def run_migrations(self, app_config: AppConfig) -> MigrationResult:
app_name=app_config.app_name
)

if self.migration_id in already_ran:
message = f"🏁 Migration {self.migration_id} has already been run"
print(message)
return MigrationResult(success=True, message=message)

migration_modules: dict[str, MigrationModule] = (
self.get_migration_modules(
app_config.resolved_migrations_folder_path
Expand Down
31 changes: 30 additions & 1 deletion tests/apps/migrations/commands/test_forwards_backwards.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from piccolo.apps.migrations.commands.forwards import forwards
from piccolo.apps.migrations.tables import Migration
from piccolo.utils.sync import run_sync
from tests.base import engines_only
from tests.base import AsyncMock, engines_only
from tests.example_apps.music.tables import (
Band,
Concert,
Expand Down Expand Up @@ -141,6 +141,35 @@ def test_forwards_unknown_migration(self, print_: MagicMock):
in print_.mock_calls
)

@patch("piccolo.apps.migrations.commands.forwards.print")
@patch(
"piccolo.apps.migrations.commands.forwards.Migration.get_migrations_which_ran", # noqa: E501
new_callable=AsyncMock,
)
def test_already_ran(
self,
get_migrations_which_ran: MagicMock,
print_: MagicMock,
):
"""
When a specific migration ID has already run, but there are later
migrations which haven't, then the command should succeed rather than
reporting the migration as unrecognised.

https://github.com/piccolo-orm/piccolo/issues/1359

"""
migration_id = "2020-12-17T18:44:30"

get_migrations_which_ran.return_value = [migration_id]

run_sync(forwards(app_name="music", migration_id=migration_id))

self.assertIn(
call(f"🏁 Migration {migration_id} has already been run"),
print_.mock_calls,
)

@patch("piccolo.apps.migrations.commands.backwards.print")
def test_backwards_unknown_migration(self, print_: MagicMock):
"""
Expand Down
Loading