Skip to content

Commit

Permalink
Experiment with indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Kubov committed Jul 4, 2024
1 parent 3d84f5a commit 155adf9
Showing 1 changed file with 70 additions and 1 deletion.
71 changes: 70 additions & 1 deletion pymess/migrations/0030_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import django.db.models.deletion
from django.db import migrations, models

from utils.migrations import migration_print


Expand Down Expand Up @@ -91,6 +92,41 @@ class Migration(migrations.Migration):
field=models.SlugField(blank=True, max_length=100, null=True),
),

# We add indexes to speed-up insertion.

migrations.AddIndex(
model_name='dialermessage',
index=models.Index(fields=['template_old'], name='pymess_dial_templat_8f8f2d_idx'),
),
migrations.AddIndex(
model_name='dialertemplatedisallowedobject',
index=models.Index(fields=['template_old'], name='pymess_dial_templat_94e496_idx'),
),
migrations.AddIndex(
model_name='emailmessage',
index=models.Index(fields=['template_old'], name='pymess_emai_templat_751e5f_idx'),
),
migrations.AddIndex(
model_name='emailtemplateattachment',
index=models.Index(fields=['template_old'], name='pymess_emai_templat_1e5760_idx'),
),
migrations.AddIndex(
model_name='emailtemplatedisallowedobject',
index=models.Index(fields=['template_old'], name='pymess_emai_templat_799bce_idx'),
),
migrations.AddIndex(
model_name='outputsmsmessage',
index=models.Index(fields=['template_old'], name='pymess_outp_templat_f4eb8d_idx'),
),
migrations.AddIndex(
model_name='pushnotificationmessage',
index=models.Index(fields=['template_old'], name='pymess_push_templat_8d32eb_idx'),
),
migrations.AddIndex(
model_name='smstemplatedisallowedobject',
index=models.Index(fields=['template_old'], name='pymess_smst_templat_1a34e4_idx'),
),

# 2. Rename 'template' -> 'template_old'

migrations.RenameField(
Expand Down Expand Up @@ -273,7 +309,40 @@ class Migration(migrations.Migration):

migrations.RunPython(create_template_ids_from_slugs),

# 8. We can safely remove old `template_old` field.
# 8. We can safely remove old `template_old` fields and their indexes.

migrations.RemoveIndex(
model_name='dialermessage',
name='pymess_dial_templat_8f8f2d_idx',
),
migrations.RemoveIndex(
model_name='dialertemplatedisallowedobject',
name='pymess_dial_templat_94e496_idx',
),
migrations.RemoveIndex(
model_name='emailmessage',
name='pymess_emai_templat_751e5f_idx',
),
migrations.RemoveIndex(
model_name='emailtemplateattachment',
name='pymess_emai_templat_1e5760_idx',
),
migrations.RemoveIndex(
model_name='emailtemplatedisallowedobject',
name='pymess_emai_templat_799bce_idx',
),
migrations.RemoveIndex(
model_name='outputsmsmessage',
name='pymess_outp_templat_f4eb8d_idx',
),
migrations.RemoveIndex(
model_name='pushnotificationmessage',
name='pymess_push_templat_8d32eb_idx',
),
migrations.RemoveIndex(
model_name='smstemplatedisallowedobject',
name='pymess_smst_templat_1a34e4_idx',
),

migrations.RemoveField(
model_name='dialertemplatedisallowedobject',
Expand Down

0 comments on commit 155adf9

Please sign in to comment.