From acb5b926b8d971513fcd625ed24fa749f71248ee Mon Sep 17 00:00:00 2001 From: Ryan Hiebert Date: Wed, 24 Jul 2024 01:01:03 -0500 Subject: [PATCH] Change the default to Safe.always --- HISTORY.rst | 2 ++ .../management/commands/safemigrate.py | 3 ++- tests/safemigrate_test.py | 21 ++++++++++++------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 11a4e9f..f0a154a 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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) ++++++++++++++++ diff --git a/src/django_safemigrate/management/commands/safemigrate.py b/src/django_safemigrate/management/commands/safemigrate.py index 054e1ce..d1313ac 100644 --- a/src/django_safemigrate/management/commands/safemigrate.py +++ b/src/django_safemigrate/management/commands/safemigrate.py @@ -2,6 +2,7 @@ Migration safety is enforced by a pre_migrate signal receiver. """ + from __future__ import annotations from enum import Enum @@ -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(): diff --git a/tests/safemigrate_test.py b/tests/safemigrate_test.py index 357b25d..42b7036 100644 --- a/tests/safemigrate_test.py +++ b/tests/safemigrate_test.py @@ -1,4 +1,5 @@ """Unit tests for the safemigrate command.""" + from datetime import timedelta from io import StringIO @@ -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.""" @@ -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, ),