64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
|
|
"""
|
||
|
|
Data migration: reorder the five Pope cards.
|
||
|
|
|
||
|
|
New assignment (card number → title):
|
||
|
|
1 → Chancellor 2 → President 3 → Tsar 4 → Chairman 5 → Emperor
|
||
|
|
"""
|
||
|
|
from django.db import migrations
|
||
|
|
|
||
|
|
|
||
|
|
POPE_RENAMES = {
|
||
|
|
1: ("Pope 1: Chancellor", "pope-1-chancellor"),
|
||
|
|
2: ("Pope 2: President", "pope-2-president"),
|
||
|
|
3: ("Pope 3: Tsar", "pope-3-tsar"),
|
||
|
|
4: ("Pope 4: Chairman", "pope-4-chairman"),
|
||
|
|
5: ("Pope 5: Emperor", "pope-5-emperor"),
|
||
|
|
}
|
||
|
|
|
||
|
|
POPE_ORIGINALS = {
|
||
|
|
1: ("Pope 1: President", "pope-1-president"),
|
||
|
|
2: ("Pope 2: Tsar", "pope-2-tsar"),
|
||
|
|
3: ("Pope 3: Chairman", "pope-3-chairman"),
|
||
|
|
4: ("Pope 4: Emperor", "pope-4-emperor"),
|
||
|
|
5: ("Pope 5: Chancellor", "pope-5-chancellor"),
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
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 POPE_RENAMES.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 POPE_ORIGINALS.items():
|
||
|
|
TarotCard.objects.filter(
|
||
|
|
deck_variant=earthman, arcana="MAJOR", number=number
|
||
|
|
).update(name=old_name, slug=old_slug)
|
||
|
|
|
||
|
|
|
||
|
|
class Migration(migrations.Migration):
|
||
|
|
|
||
|
|
dependencies = [
|
||
|
|
("epic", "0015_rename_classical_element_earth_to_stone"),
|
||
|
|
]
|
||
|
|
|
||
|
|
operations = [
|
||
|
|
migrations.RunPython(rename_forward, reverse_code=rename_reverse),
|
||
|
|
]
|