diff --git a/src/apps/epic/migrations/0020_rename_earthman_pope_cards_2_5.py b/src/apps/epic/migrations/0020_rename_earthman_pope_cards_2_5.py new file mode 100644 index 0000000..2a18b8e --- /dev/null +++ b/src/apps/epic/migrations/0020_rename_earthman_pope_cards_2_5.py @@ -0,0 +1,63 @@ +""" +Data migration: rename Pope cards 2–5 in the Earthman deck. + + 2: "Pope 2: The Despot" → "Pope 2: The Occultist" + 3: "Pope 3: The Capitalist" → "Pope 3: The Despot" + 4: "Pope 4: The Fascist" → "Pope 4: The Capitalist" + 5: "Pope 5: The War Machine" → "Pope 5: The Fascist" +""" +from django.db import migrations + + +NEW_NAMES = { + 2: ("Pope 2: The Occultist", "pope-2-the-occultist"), + 3: ("Pope 3: The Despot", "pope-3-the-despot"), + 4: ("Pope 4: The Capitalist","pope-4-the-capitalist"), + 5: ("Pope 5: The Fascist", "pope-5-the-fascist"), +} + +OLD_NAMES = { + 2: ("Pope 2: The Despot", "pope-2-the-despot"), + 3: ("Pope 3: The Capitalist", "pope-3-the-capitalist"), + 4: ("Pope 4: The Fascist", "pope-4-the-fascist"), + 5: ("Pope 5: The War Machine", "pope-5-the-war-machine"), +} + + +def rename_forward(apps, schema_editor): + TarotCard = apps.get_model("epic", "TarotCard") + DeckVariant = apps.get_model("epic", "DeckVariant") + + earthman = DeckVariant.objects.filter(slug="earthman").first() + if not earthman: + return + + for number, (new_name, new_slug) in NEW_NAMES.items(): + TarotCard.objects.filter( + deck_variant=earthman, arcana="MAJOR", number=number + ).update(name=new_name, slug=new_slug) + + +def rename_reverse(apps, schema_editor): + TarotCard = apps.get_model("epic", "TarotCard") + DeckVariant = apps.get_model("epic", "DeckVariant") + + earthman = DeckVariant.objects.filter(slug="earthman").first() + if not earthman: + return + + for number, (old_name, old_slug) in OLD_NAMES.items(): + TarotCard.objects.filter( + deck_variant=earthman, arcana="MAJOR", number=number + ).update(name=old_name, slug=old_slug) + + +class Migration(migrations.Migration): + + dependencies = [ + ("epic", "0019_rename_earthman_schiz_and_popes"), + ] + + operations = [ + migrations.RunPython(rename_forward, reverse_code=rename_reverse), + ]