Skip to content

Commit

Permalink
Add python migration code to fix existing data
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewelwell committed Aug 31, 2023
1 parent 9c57312 commit d6a9d07
Showing 1 changed file with 31 additions and 5 deletions.
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,
),
]

0 comments on commit d6a9d07

Please sign in to comment.