diff --git a/src/apps/drama/migrations/0003_grant_super_notes_to_existing_superusers.py b/src/apps/drama/migrations/0003_grant_super_notes_to_existing_superusers.py new file mode 100644 index 0000000..b742842 --- /dev/null +++ b/src/apps/drama/migrations/0003_grant_super_notes_to_existing_superusers.py @@ -0,0 +1,27 @@ +"""Backfill super-schizo and super-nomad Notes for all existing superusers.""" +from django.db import migrations +from django.utils import timezone + + +def grant_super_notes(apps, schema_editor): + User = apps.get_model("lyric", "User") + Note = apps.get_model("drama", "Note") + now = timezone.now() + for user in User.objects.filter(is_superuser=True): + for slug in ("super-schizo", "super-nomad"): + Note.objects.get_or_create( + user=user, slug=slug, + defaults={"earned_at": now}, + ) + + +class Migration(migrations.Migration): + + dependencies = [ + ("drama", "0002_initial"), + ("lyric", "0001_initial"), + ] + + operations = [ + migrations.RunPython(grant_super_notes, migrations.RunPython.noop), + ]