Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Commit

Permalink
refactor: create redis fields before altering
Browse files Browse the repository at this point in the history
  • Loading branch information
gabor-boros committed Aug 30, 2021
1 parent 08ae12b commit c668293
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 20 deletions.
20 changes: 0 additions & 20 deletions instance/migrations/0143_add_redis_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@
import instance.models.utils


def generate_credentials(apps, schema_editor):
RedisServer = apps.get_model('instance', 'RedisServer')
for row in RedisServer.objects.all():
row.redis_username = instance.models.mixins.redis.random_username()
row.redis_password = instance.models.mixins.redis.random_password()
row.save(update_fields=['redis_username', 'redis_password'])



class Migration(migrations.Migration):

dependencies = [
Expand Down Expand Up @@ -64,15 +55,4 @@ class Migration(migrations.Migration):
name='redis_server',
field=models.ForeignKey(blank=True, default=instance.models.mixins.redis.select_random_redis_server, null=True, on_delete=django.db.models.deletion.PROTECT, to='instance.RedisServer'),
),
migrations.RunPython(generate_credentials, reverse_code=migrations.RunPython.noop),
migrations.AlterField(
model_name='openedxinstance',
name='redis_username',
field=models.CharField(max_length=32, unique=True),
),
migrations.AlterField(
model_name='openedxinstance',
name='redis_password',
field=models.CharField(max_length=64, null=False),
),
]
37 changes: 37 additions & 0 deletions instance/migrations/0144_make_redis_username_unique.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 2.2.24 on 2021-08-13 08:53

from django.db import migrations, models
import django.db.models.deletion
import django_extensions.db.fields
import instance.models.mixins.redis
import instance.models.utils


def generate_credentials(apps, schema_editor):
RedisServer = apps.get_model('instance', 'RedisServer')
for row in RedisServer.objects.all():
row.redis_username = instance.models.mixins.redis.random_username()
row.redis_password = instance.models.mixins.redis.random_password()
row.save(update_fields=['redis_username', 'redis_password'])



class Migration(migrations.Migration):

dependencies = [
('instance', '0143_add_redis_server'),
]

operations = [
migrations.RunPython(generate_credentials, reverse_code=migrations.RunPython.noop),
migrations.AlterField(
model_name='openedxinstance',
name='redis_username',
field=models.CharField(max_length=32, unique=True),
),
migrations.AlterField(
model_name='openedxinstance',
name='redis_password',
field=models.CharField(max_length=64, null=False),
),
]

0 comments on commit c668293

Please sign in to comment.