diff --git a/backend/experiment/migrations/0059_alter_experiment_slug.py b/backend/experiment/migrations/0059_alter_experiment_slug.py deleted file mode 100644 index 62bfb1f29..000000000 --- a/backend/experiment/migrations/0059_alter_experiment_slug.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 4.2.16 on 2024-11-05 08:10 - -from django.db import migrations, models -import experiment.validators - - -class Migration(migrations.Migration): - - dependencies = [ - ('experiment', '0058_remove_socialmediaconfig_content_and_more'), - ] - - operations = [ - migrations.AlterField( - model_name='experiment', - name='slug', - field=models.SlugField(max_length=64, unique=True, validators=[experiment.validators.block_slug_validator]), - ), - ] diff --git a/backend/experiment/migrations/0060_experiment_slug_temp.py b/backend/experiment/migrations/0060_experiment_slug_temp.py new file mode 100644 index 000000000..a285000c0 --- /dev/null +++ b/backend/experiment/migrations/0060_experiment_slug_temp.py @@ -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]), + ), + ] diff --git a/backend/experiment/migrations/0061_migrate_slugs_to_unique_temp_field.py b/backend/experiment/migrations/0061_migrate_slugs_to_unique_temp_field.py new file mode 100644 index 000000000..c2d9978e9 --- /dev/null +++ b/backend/experiment/migrations/0061_migrate_slugs_to_unique_temp_field.py @@ -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), + ] diff --git a/backend/experiment/migrations/0062_rename_slug_temp_to_slug.py b/backend/experiment/migrations/0062_rename_slug_temp_to_slug.py new file mode 100644 index 000000000..cd2507a7a --- /dev/null +++ b/backend/experiment/migrations/0062_rename_slug_temp_to_slug.py @@ -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' + ) + ] diff --git a/backend/experiment/migrations/0063_remove_old_slug.py b/backend/experiment/migrations/0063_remove_old_slug.py new file mode 100644 index 000000000..b1cc76d54 --- /dev/null +++ b/backend/experiment/migrations/0063_remove_old_slug.py @@ -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', + ), + ] diff --git a/backend/experiment/models.py b/backend/experiment/models.py index af971e499..6657720a1 100644 --- a/backend/experiment/models.py +++ b/backend/experiment/models.py @@ -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)