Skip to content

Commit

Permalink
Write detected migrations even when all are safe
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhiebert committed Jul 24, 2024
1 parent 7798942 commit 4d0acee
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/django_safemigrate/management/commands/safemigrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Migration safety is enforced by a pre_migrate signal receiver.
"""

from __future__ import annotations

from enum import Enum
Expand Down Expand Up @@ -133,7 +134,8 @@ def pre_migrate_receiver(self, *, plan, **_):
ready, protected = filter_migrations(migrations)

if not protected:
return # No migrations to protect.
self.detect(migrations)
return # Run all the migrations

# Display the migrations that are protected
self.stdout.write(self.style.MIGRATE_HEADING("Protected migrations:"))
Expand Down Expand Up @@ -175,17 +177,21 @@ def pre_migrate_receiver(self, *, plan, **_):

# Only mark migrations as detected if not faking
if not self.fake:
# The detection datetime is what's used to determine if an
# after_deploy() with a delay can be migrated or not.
for migration in migrations:
SafeMigration.objects.get_or_create(
app=migration.app_label, name=migration.name
)
self.detect(migrations)

# Swap out the items in the plan with the safe migrations.
# None are backward, so we can always set backward to False.
plan[:] = [(migration, False) for migration in ready]

def detect(self, migrations):
"""Detect and record migrations to the database."""
# The detection datetime is what's used to determine if an
# after_deploy() with a delay can be migrated or not.
for migration in migrations:
SafeMigration.objects.get_or_create(
app=migration.app_label, name=migration.name
)

def delayed(self, migrations):
"""Handle delayed migrations."""
# Display delayed migrations if they exist:
Expand Down

0 comments on commit 4d0acee

Please sign in to comment.