83 lines
2.4 KiB
Python
83 lines
2.4 KiB
Python
"""
|
|
Data migration: rename Earthman court cards at positions 11 and 12.
|
|
|
|
Old naming (from 0010): Jack (11) / Cavalier (12)
|
|
New naming: Maid (11) / Jack (12)
|
|
|
|
Must rename 11 → Maid first so the "jack-of-*-em" slugs are free
|
|
before the 12s claim them.
|
|
"""
|
|
from django.db import migrations
|
|
|
|
|
|
SUITS = ["Wands", "Cups", "Swords", "Coins"]
|
|
|
|
|
|
def rename_court_cards(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
|
|
|
|
# Step 1: Jack (11) → Maid — frees up jack-of-*-em slugs
|
|
for suit in SUITS:
|
|
suit_slug = suit.lower()
|
|
TarotCard.objects.filter(
|
|
deck_variant=earthman, number=11, slug=f"jack-of-{suit_slug}-em"
|
|
).update(
|
|
name=f"Maid of {suit}",
|
|
slug=f"maid-of-{suit_slug}-em",
|
|
)
|
|
|
|
# Step 2: Cavalier (12) → Jack — takes the now-free jack-of-*-em slugs
|
|
for suit in SUITS:
|
|
suit_slug = suit.lower()
|
|
TarotCard.objects.filter(
|
|
deck_variant=earthman, number=12, slug=f"cavalier-of-{suit_slug}-em"
|
|
).update(
|
|
name=f"Jack of {suit}",
|
|
slug=f"jack-of-{suit_slug}-em",
|
|
)
|
|
|
|
|
|
def reverse_court_cards(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
|
|
|
|
# Step 1: Jack (12) → Cavalier — frees up jack-of-*-em slugs
|
|
for suit in SUITS:
|
|
suit_slug = suit.lower()
|
|
TarotCard.objects.filter(
|
|
deck_variant=earthman, number=12, slug=f"jack-of-{suit_slug}-em"
|
|
).update(
|
|
name=f"Cavalier of {suit}",
|
|
slug=f"cavalier-of-{suit_slug}-em",
|
|
)
|
|
|
|
# Step 2: Maid (11) → Jack
|
|
for suit in SUITS:
|
|
suit_slug = suit.lower()
|
|
TarotCard.objects.filter(
|
|
deck_variant=earthman, number=11, slug=f"maid-of-{suit_slug}-em"
|
|
).update(
|
|
name=f"Jack of {suit}",
|
|
slug=f"jack-of-{suit_slug}-em",
|
|
)
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
("epic", "0010_seed_deck_variants_and_earthman"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(rename_court_cards, reverse_code=reverse_court_cards),
|
|
]
|