-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
256627e
commit c70f821
Showing
3 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
docker-app/qfieldcloud/core/migrations/0057_secrets_migration.py
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,42 @@ | ||
import os | ||
|
||
import django_cryptography.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
def rotate_secret_from_old_to_new(apps, schema_editor): | ||
Secret = apps.get_model("core", "Secret") | ||
|
||
for secret in Secret.objects.all(): | ||
secret.value = secret.old_value | ||
secret.save() | ||
print(secret.value, secret.old_value) | ||
|
||
dependencies = [ | ||
("core", "0056_projectpermissionsview"), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name="secret", | ||
old_name="value", | ||
new_name="old_value", | ||
), | ||
migrations.AddField( | ||
model_name="secret", | ||
name="value", | ||
field=django_cryptography.fields.encrypt( | ||
models.TextField(null=True), | ||
key=os.environ.get("CRYPTOGRAPHY_KEY_20220612").encode(), | ||
), | ||
), | ||
migrations.RunPython( | ||
rotate_secret_from_old_to_new, | ||
migrations.RunPython.noop, | ||
), | ||
migrations.RemoveField( | ||
model_name="secret", | ||
name="old_value", | ||
), | ||
] |
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