Allow operation_names to be a list instead of a singular item
This commit is contained in:
parent
2251475bbe
commit
65a7622582
7 changed files with 104 additions and 42 deletions
|
|
@ -0,0 +1,59 @@
|
|||
# Generated by Django 6.0.1 on 2026-01-17 05:32
|
||||
from __future__ import annotations
|
||||
|
||||
from django.db import migrations
|
||||
from django.db import models
|
||||
|
||||
|
||||
def migrate_operation_name_to_list(apps, schema_editor) -> None: # noqa: ANN001, ARG001
|
||||
"""Convert operation_name string values to operation_names list."""
|
||||
DropCampaign = apps.get_model("twitch", "DropCampaign")
|
||||
for campaign in DropCampaign.objects.all():
|
||||
if campaign.operation_name and campaign.operation_name.strip():
|
||||
campaign.operation_names = [campaign.operation_name.strip()]
|
||||
campaign.save(update_fields=["operation_names"])
|
||||
|
||||
|
||||
def reverse_operation_names_to_string(apps, schema_editor) -> None: # noqa: ARG001, ANN001
|
||||
"""Convert operation_names list back to operation_name string (first item only)."""
|
||||
DropCampaign = apps.get_model("twitch", "DropCampaign")
|
||||
for campaign in DropCampaign.objects.all():
|
||||
if campaign.operation_names:
|
||||
campaign.operation_name = campaign.operation_names[0]
|
||||
campaign.save(update_fields=["operation_name"])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
"""Rename operation_name field to operation_names and convert to list."""
|
||||
|
||||
dependencies = [
|
||||
("twitch", "0006_add_chat_badges"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveIndex(
|
||||
model_name="dropcampaign",
|
||||
name="twitch_drop_operati_8cfeb5_idx",
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="dropcampaign",
|
||||
name="operation_names",
|
||||
field=models.JSONField(
|
||||
blank=True,
|
||||
default=list,
|
||||
help_text="List of GraphQL operation names used to fetch this campaign data (e.g., ['ViewerDropsDashboard', 'Inventory']).", # noqa: E501
|
||||
),
|
||||
),
|
||||
migrations.RunPython(
|
||||
migrate_operation_name_to_list,
|
||||
reverse_operation_names_to_string,
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="dropcampaign",
|
||||
index=models.Index(fields=["operation_names"], name="twitch_drop_operati_fe3bc8_idx"),
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="dropcampaign",
|
||||
name="operation_name",
|
||||
),
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue