-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace AbstractRecurringUserPlan.has_automatic_renewal with Abstract…
…RecurringUserPlan.renewal_triggered_by
- Loading branch information
1 parent
8581f34
commit 33ffece
Showing
10 changed files
with
542 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
plans/migrations/0013_alter_recurringuserplan_has_automatic_renewal_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Generated by Django 4.2.11 on 2024-04-09 10:20 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("plans", "0012_planpricing_visible"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="recurringuserplan", | ||
name="has_automatic_renewal", | ||
field=models.BooleanField( | ||
db_column="has_automatic_renewal", | ||
default=False, | ||
help_text="Automatic renewal is enabled for associated plan. If False, the plan renewal can be still initiated by user.", | ||
verbose_name="has automatic plan renewal", | ||
), | ||
), | ||
migrations.RenameField( | ||
model_name="recurringuserplan", | ||
old_name="has_automatic_renewal", | ||
new_name="_has_automatic_renewal_backup_deprecated", | ||
), | ||
migrations.AddField( | ||
model_name="recurringuserplan", | ||
name="renewal_triggered_by", | ||
field=models.IntegerField( | ||
choices=[(1, "other"), (2, "user"), (3, "task")], | ||
db_index=True, | ||
default=2, | ||
help_text="The source of the associated plan's renewal (USER = user-initiated renewal, TASK = autorenew_account-task-initiated renewal, OTHER = renewal is triggered using another mechanism).", | ||
verbose_name="renewal triggered by", | ||
), | ||
), | ||
] |
88 changes: 88 additions & 0 deletions
88
...0014_recurringuserplan_has_automatic_renewal_backup_deprecated_to_renewal_triggered_by.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Generated by Django 4.2.11 on 2024-04-10 12:50 | ||
|
||
from enum import IntEnum | ||
|
||
from django.db import migrations | ||
|
||
|
||
def _recurringuserplan_has_automatic_renewal_backup_deprecated_to_renewal_triggered_by( | ||
apps, schema_editor | ||
): | ||
RecurringUserPlan = apps.get_model("plans", "RecurringUserPlan") | ||
recurringuserplans_changed = ( | ||
RecurringUserPlan.objects.select_for_update() | ||
.exclude( | ||
_has_automatic_renewal_backup_deprecated=True, | ||
renewal_triggered_by=_RenewalTriggeredByEnum.TASK, | ||
) | ||
.exclude( | ||
_has_automatic_renewal_backup_deprecated=False, | ||
renewal_triggered_by=_RenewalTriggeredByEnum.USER, | ||
) | ||
) | ||
for recurringuserplan_changed in recurringuserplans_changed: | ||
print( | ||
"RecurringUserPlan's renewal_triggered_by will be overwritten:", | ||
recurringuserplan_changed.pk, | ||
) | ||
RecurringUserPlan.objects.filter( | ||
_has_automatic_renewal_backup_deprecated=True | ||
).update(renewal_triggered_by=_RenewalTriggeredByEnum.TASK) | ||
RecurringUserPlan.objects.filter( | ||
_has_automatic_renewal_backup_deprecated=False | ||
).update(renewal_triggered_by=_RenewalTriggeredByEnum.USER) | ||
|
||
|
||
def _recurringuserplan_renewal_triggered_by_to_has_automatic_renewal_backup_deprecated( | ||
apps, schema_editor | ||
): | ||
RecurringUserPlan = apps.get_model("plans", "RecurringUserPlan") | ||
recurringuserplans_changed = ( | ||
RecurringUserPlan.objects.select_for_update() | ||
.exclude( | ||
renewal_triggered_by__in={ | ||
_RenewalTriggeredByEnum.TASK, | ||
_RenewalTriggeredByEnum.OTHER, | ||
}, | ||
_has_automatic_renewal_backup_deprecated=True, | ||
) | ||
.exclude( | ||
renewal_triggered_by=_RenewalTriggeredByEnum.USER, | ||
_has_automatic_renewal_backup_deprecated=False, | ||
) | ||
) | ||
for recurringuserplan_changed in recurringuserplans_changed: | ||
print( | ||
"RecurringUserPlan's _has_automatic_renewal_backup_deprecated will be overwritten:", | ||
recurringuserplan_changed.pk, | ||
) | ||
RecurringUserPlan.objects.filter( | ||
renewal_triggered_by__in={ | ||
_RenewalTriggeredByEnum.TASK, | ||
_RenewalTriggeredByEnum.OTHER, | ||
} | ||
).update(_has_automatic_renewal_backup_deprecated=True) | ||
RecurringUserPlan.objects.filter( | ||
renewal_triggered_by=_RenewalTriggeredByEnum.USER | ||
).update(_has_automatic_renewal_backup_deprecated=False) | ||
RecurringUserPlan.objects.update(renewal_triggered_by=_RenewalTriggeredByEnum.USER) | ||
|
||
|
||
class _RenewalTriggeredByEnum(IntEnum): | ||
OTHER = 1 | ||
USER = 2 | ||
TASK = 3 | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("plans", "0013_alter_recurringuserplan_has_automatic_renewal_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
_recurringuserplan_has_automatic_renewal_backup_deprecated_to_renewal_triggered_by, | ||
reverse_code=_recurringuserplan_renewal_triggered_by_to_has_automatic_renewal_backup_deprecated, | ||
) | ||
] |
Oops, something went wrong.