Skip to content

Commit

Permalink
Migrate slug to new unique field
Browse files Browse the repository at this point in the history
  • Loading branch information
Evert-R committed Nov 15, 2024
1 parent ab4aafd commit 0ea57ba
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 20 deletions.
19 changes: 0 additions & 19 deletions backend/experiment/migrations/0059_alter_experiment_slug.py

This file was deleted.

19 changes: 19 additions & 0 deletions backend/experiment/migrations/0060_experiment_slug_temp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.16 on 2024-11-15 09:00

from django.db import migrations, models
import experiment.validators


class Migration(migrations.Migration):

dependencies = [
('experiment', '0059_add_social_media_config'),
]

operations = [
migrations.AddField(
model_name='experiment',
name='slug_temp',
field=models.SlugField(null=True, max_length=64, unique=True, validators=[experiment.validators.block_slug_validator]),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.16 on 2024-11-15 09:01

from django.db import migrations


class Migration(migrations.Migration):

def forwards_func(apps, schema_editor):
Experiment = apps.get_model('experiment', 'Experiment')
for experiment in Experiment.objects.all():
experiment.slug_temp = experiment.slug
experiment.save()

def reverse_func(apps, schema_editor):
Experiment = apps.get_model('experiment', 'Experiment')
for experiment in Experiment.objects.all():
experiment.slug = experiment.slug_temp
experiment.save()

dependencies = [
('experiment', '0060_experiment_slug_temp'),
]

operations = [
migrations.RunPython(forwards_func, reverse_func),
]
23 changes: 23 additions & 0 deletions backend/experiment/migrations/0062_rename_slug_temp_to_slug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.16 on 2024-11-15 09:09

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('experiment', '0061_migrate_slugs_to_unique_temp_field'),
]

operations = [
migrations.RenameField(
model_name='Experiment',
old_name='slug',
new_name='old_slug'
),
migrations.RenameField(
model_name='Experiment',
old_name='slug_temp',
new_name='slug'
)
]
17 changes: 17 additions & 0 deletions backend/experiment/migrations/0063_remove_old_slug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.16 on 2024-11-15 09:14

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('experiment', '0062_rename_slug_temp_to_slug'),
]

operations = [
migrations.RemoveField(
model_name='Experiment',
name='old_slug',
),
]
6 changes: 5 additions & 1 deletion backend/experiment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ class Experiment(models.Model):
phases (Queryset[Phase]): Queryset of Phase instances
"""

slug = models.SlugField(max_length=64, unique=True, validators=[experiment_slug_validator])
slug = models.SlugField(db_index=True,
max_length=64,
unique=True,
null=True,
validators=[experiment_slug_validator])
translated_content = models.QuerySet["ExperimentTranslatedContent"]
theme_config = models.ForeignKey("theme.ThemeConfig", blank=True, null=True, on_delete=models.SET_NULL)
active = models.BooleanField(default=True)
Expand Down

0 comments on commit 0ea57ba

Please sign in to comment.