UPDATE
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def enable_default_feature_access(apps, schema_editor):
|
||||
AccessFeature = apps.get_model("access_control", "AccessFeature")
|
||||
|
||||
from access_control.catalog import DEFAULT_ACCESS_FEATURES
|
||||
|
||||
default_enabled_codes = [item["code"] for item in DEFAULT_ACCESS_FEATURES if item.get("default_enabled", False)]
|
||||
AccessFeature.objects.filter(code__in=default_enabled_codes).update(default_enabled=True)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("access_control", "0003_seed_default_access_rules"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(enable_default_feature_access, migrations.RunPython.noop),
|
||||
]
|
||||
@@ -0,0 +1,26 @@
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def backfill_farm_subscription_plans(apps, schema_editor):
|
||||
SubscriptionPlan = apps.get_model("access_control", "SubscriptionPlan")
|
||||
FarmHub = apps.get_model("farm_hub", "FarmHub")
|
||||
|
||||
default_plan = (
|
||||
SubscriptionPlan.objects.filter(is_active=True, metadata__is_default=True).order_by("name").first()
|
||||
or SubscriptionPlan.objects.filter(code="gold", is_active=True).first()
|
||||
)
|
||||
if default_plan is None:
|
||||
return
|
||||
|
||||
FarmHub.objects.filter(subscription_plan__isnull=True).update(subscription_plan=default_plan)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("access_control", "0004_enable_default_feature_access"),
|
||||
("farm_hub", "0007_farmhub_subscription_plan"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(backfill_farm_subscription_plans, migrations.RunPython.noop),
|
||||
]
|
||||
Reference in New Issue
Block a user