Skip to content

Commit

Permalink
Change the default to Safe.always
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhiebert committed Jul 25, 2024
1 parent 7798942 commit acb5b92
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Pending
* ``Safe.always()``
* Add support for allowing a ``Safe.after_deploy(delay=timedelta())``
migration to be migrated after the delay has passed.
* 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
3 changes: 2 additions & 1 deletion 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 All @@ -26,7 +27,7 @@ class SafeMigrate(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():
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 acb5b92

Please sign in to comment.