-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add python migration code to fix existing data
- Loading branch information
1 parent
9c57312
commit d6a9d07
Showing
1 changed file
with
31 additions
and
5 deletions.
There are no files selected for viewing
36 changes: 31 additions & 5 deletions
36
api/organisations/migrations/0046_allow_allowed_projects_to_be_null.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 |
---|---|---|
@@ -1,18 +1,44 @@ | ||
# Generated by Django 3.2.20 on 2023-08-31 11:31 | ||
|
||
from django.apps.registry import Apps | ||
from django.db import migrations, models | ||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor | ||
|
||
|
||
class Migration(migrations.Migration): | ||
def update_allowed_projects_for_all_paid_subscriptions( | ||
apps: Apps, schema_editor: BaseDatabaseSchemaEditor | ||
) -> None: | ||
organisation_subscription_information_cache_model = apps.get_model( | ||
"organisations", "organisationsubscriptioninformationcache" | ||
) | ||
organisation_subscription_information_cache_model.objects.exclude( | ||
organisation__subscription__plan="free" | ||
).update(allowed_projects=None) | ||
|
||
|
||
def update_allowed_projects_for_all_free_subscriptions( | ||
apps: Apps, schema_editor: BaseDatabaseSchemaEditor | ||
) -> None: | ||
organisation_subscription_information_cache_model = apps.get_model( | ||
"organisations", "organisationsubscriptioninformationcache" | ||
) | ||
organisation_subscription_information_cache_model.objects.exclude( | ||
organisation__subscription__plan="free" | ||
).update(allowed_projects=1) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('organisations', '0045_auto_20230802_1956'), | ||
("organisations", "0045_auto_20230802_1956"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='organisationsubscriptioninformationcache', | ||
name='allowed_projects', | ||
model_name="organisationsubscriptioninformationcache", | ||
name="allowed_projects", | ||
field=models.IntegerField(default=1, blank=True, null=True), | ||
), | ||
migrations.RunPython( | ||
update_allowed_projects_for_all_paid_subscriptions, | ||
reverse_code=update_allowed_projects_for_all_free_subscriptions, | ||
), | ||
] |