Skip to content

Commit

Permalink
Set elidable on RunPython operations in migrations
Browse files Browse the repository at this point in the history
Any RunPython operation that only migrated existing data (that is, did
not create data) can be safely elided by Django when we run
`squashmigrations`.
  • Loading branch information
jchristgit committed Mar 31, 2024
1 parent 341b00b commit 9717773
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 10 deletions.
Expand Up @@ -19,5 +19,5 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RunPython(migrate_hidden_warnings_to_notes),
migrations.RunPython(migrate_hidden_warnings_to_notes, elidable=True),
]
Expand Up @@ -60,5 +60,5 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RunPython(migrate_nominations_to_new_model),
migrations.RunPython(migrate_nominations_to_new_model, elidable=True),
]
Expand Up @@ -100,6 +100,6 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RunPython(migrate_inactive_types_to_inactive, reverse_migration),
migrations.RunPython(migrate_multiple_active_infractions_per_user_to_one, reverse_migration)
migrations.RunPython(migrate_inactive_types_to_inactive, reverse_migration, elidable=True),
migrations.RunPython(migrate_multiple_active_infractions_per_user_to_one, reverse_migration, elidable=True)
]
Expand Up @@ -58,7 +58,7 @@ class Migration(migrations.Migration):
bases=(pydis_site.apps.api.models.mixins.ModelReprMixin, models.Model),
options={'ordering': ('-inserted_at',), 'verbose_name_plural': 'nomination entries'}
),
migrations.RunPython(migrate_nominations, unmigrate_nominations),
migrations.RunPython(migrate_nominations, unmigrate_nominations, elidable=True),
migrations.RemoveField(
model_name='nomination',
name='actor',
Expand Down
2 changes: 1 addition & 1 deletion pydis_site/apps/api/migrations/0074_voice_mute.py
Expand Up @@ -32,5 +32,5 @@ class Migration(migrations.Migration):
name='type',
field=models.CharField(choices=[('note', 'Note'), ('warning', 'Warning'), ('watch', 'Watch'), ('mute', 'Mute'), ('kick', 'Kick'), ('ban', 'Ban'), ('superstar', 'Superstar'), ('voice_ban', 'Voice Ban'), ('voice_mute', 'Voice Mute')], help_text='The type of the infraction.', max_length=10),
),
migrations.RunPython(migrate_infractions, unmigrate_infractions)
migrations.RunPython(migrate_infractions, unmigrate_infractions, elidable=True)
]
Expand Up @@ -22,5 +22,5 @@ class Migration(migrations.Migration):
name='last_applied',
field=models.DateTimeField(default=django.utils.timezone.now, help_text='The date and time of when this infraction was last applied.'),
),
migrations.RunPython(set_last_applied_to_inserted_at)
migrations.RunPython(set_last_applied_to_inserted_at, elidable=True)
]
Expand Up @@ -21,5 +21,5 @@ class Migration(migrations.Migration):
name='type',
field=models.CharField(choices=[('note', 'Note'), ('warning', 'Warning'), ('watch', 'Watch'), ('timeout', 'Timeout'), ('kick', 'Kick'), ('ban', 'Ban'), ('superstar', 'Superstar'), ('voice_ban', 'Voice Ban'), ('voice_mute', 'Voice Mute')], help_text='The type of the infraction.', max_length=10),
),
migrations.RunPython(rename_type, migrations.RunPython.noop)
migrations.RunPython(rename_type, migrations.RunPython.noop, elidable=True)
]
3 changes: 2 additions & 1 deletion pydis_site/apps/api/migrations/0088_new_filter_schema.py
Expand Up @@ -163,7 +163,8 @@ class Migration(migrations.Migration):
),
migrations.RunPython(
code=forward, # Core of the migration
reverse_code=lambda *_: None
reverse_code=None,
elidable=True,
),
migrations.DeleteModel(
name='FilterListOld'
Expand Down
Expand Up @@ -13,4 +13,4 @@ class Migration(migrations.Migration):
("api", "0091_antispam_filter_list"),
]

operations = [migrations.RunPython(forward)]
operations = [migrations.RunPython(forward, elidable=True)]

0 comments on commit 9717773

Please sign in to comment.