Skip to content

Commit

Permalink
Change the default to Safe.always (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhiebert authored Jul 25, 2024
1 parent 442336b commit 0f1a375
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Pending
* Add support for allowing a ``Safe.after_deploy(delay=timedelta())``
migration to be migrated after the delay has passed.
* Rename internal enums for clarity and PEP8.
* Change the default safe marking to ``Safe.always``.
This gives a better default experience for working with third-party apps.

4.3 (2024-03-28)
++++++++++++++++
Expand Down
2 changes: 1 addition & 1 deletion src/django_safemigrate/management/commands/safemigrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Mode(Enum):

def safety(migration: Migration):
"""Determine the safety status of a migration."""
return getattr(migration, "safe", Safe.after_deploy())
return getattr(migration, "safe", Safe.always())


def safemigrate_mode():
Expand Down
21 changes: 13 additions & 8 deletions tests/safemigrate_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for the safemigrate command."""

from datetime import timedelta
from io import StringIO

Expand Down Expand Up @@ -66,11 +67,17 @@ def test_backward(self, receiver):
with pytest.raises(CommandError):
receiver(plan=plan)

def default_after(self, receiver):
"""Migrations are after by default."""
plan = [(Migration(), False)]
def test_default_always_wont_block(self, receiver):
"""Migrations are safe always by default."""
plan = [(Migration(safe=Safe.after_deploy()), False), (Migration(), False)]
receiver(plan=plan)
assert len(plan) == 0
assert len(plan) == 1

def test_default_always_wont_delay(self, receiver):
"""Migrations are safe always by default."""
plan = [(Migration(safe=Safe.before_deploy()), False), (Migration(), False)]
receiver(plan=plan)
assert len(plan) == 2

def test_all_before(self, receiver):
"""Before migrations will remain in the plan."""
Expand Down Expand Up @@ -436,16 +443,14 @@ def test_blocked_by_after_nonstrict(self, settings, receiver):
assert len(plan) == 1

def test_with_non_safe_migration_nonstrict(self, settings, receiver):
"""
Nonstrict mode allows prevents protected migrations.
In this case, that's migrations without a safe attribute.
"""
"""Nonstrict mode runs even with blocked migrations."""
settings.SAFEMIGRATE = "nonstrict"
plan = [
(
Migration(
"auth",
"0001_initial",
safe=Safe.after_deploy(),
),
False,
),
Expand Down

0 comments on commit 0f1a375

Please sign in to comment.