This repository has been archived by the owner on Aug 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: create redis fields before altering
- Loading branch information
1 parent
08ae12b
commit c668293
Showing
2 changed files
with
37 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
), | ||
] |