-
Notifications
You must be signed in to change notification settings - Fork 127
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 c0dbb98
Showing
10 changed files
with
540 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", | ||
), | ||
), | ||
] |
86 changes: 86 additions & 0 deletions
86
...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,86 @@ | ||
# 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( | ||
f"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( | ||
f"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.