Created
January 23, 2014 00:31
-
-
Save jgmize/8570501 to your computer and use it in GitHub Desktop.
Extract relations of releases to notes from legacy db to new schema in RNA
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
import json | |
from django.db.models import Q | |
from rna.models import Release, Note | |
def dump_release_notes_map(filename='release-notes-map.json'): | |
"used on the legacy side with the legacy models" | |
with open(filename, 'w') as f: | |
json.dump( | |
[(release.id, list( | |
Note.objects.filter( | |
(Q(first_version__lte=release.version) & | |
(Q(fixed_in_version__isnull=True) | | |
Q(fixed_in_version__gte=release.version))) | | |
Q(fixed_in_version=release.version), | |
Q(product__name='Firefox') | | |
Q(product__name__isnull=True)).values_list('id', flat=True))) | |
for release in Release.objects.all()], | |
f) | |
def load_release_notes_map(filename='release-notes-map.json'): | |
with open(filename) as f: | |
for release_id, note_ids in json.load(f): | |
release = Release.objects.get(id=release_id) | |
release.note_set.add(*list(Note.objects.filter(id__in=note_ids))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment