forked from mozilla/normandy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mozilla#656 from mythmon/clear-signatures
recipe-server: Add migration to remove recipe signatures again
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
recipe-server/normandy/recipes/migrations/0041_remove_invalid_signatures.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,40 @@ | ||
""" | ||
Removes signatures, so they can be easily recreated during deployment. | ||
This migration is intended to be used between "eras" of signatures. As | ||
the serialization format of recipes changes, the signatures need to | ||
also change. This could be handled automatically, but it is easier to | ||
deploy if we just remove everything in a migration, and allow the | ||
normal processes to regenerate the signatures. | ||
""" | ||
|
||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
def remove_signatures(apps, schema_editor): | ||
Recipe = apps.get_model('recipes', 'Recipe') | ||
Signature = apps.get_model('recipes', 'Signature') | ||
|
||
for recipe in Recipe.objects.exclude(signature=None): | ||
sig = recipe.signature | ||
recipe.signature = None | ||
recipe.save() | ||
sig.delete() | ||
|
||
for sig in Signature.objects.all(): | ||
sig.delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('recipes', '0040_approvalrequest_comment'), | ||
] | ||
|
||
operations = [ | ||
# This function as both a forward and reverse migration | ||
migrations.RunPython(remove_signatures, remove_signatures), | ||
] |