-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Agrego migración de borrado de periodicities duplicadas
- Loading branch information
1 parent
ad96521
commit ecd19dd
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
series_tiempo_ar_api/apps/management/migrations/delete_duplicated_metadata.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,33 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.6 on 2019-02-08 18:09 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
from series_tiempo_ar_api.apps.management import meta_keys | ||
|
||
|
||
def delete_all_but_last_periodicity(apps, schema_editor): | ||
Metadata = apps.get_model('django_datajsonar', 'Metadata') | ||
db_alias = schema_editor.connection.alias | ||
|
||
found_distributions = set() | ||
periodicites= Metadata.objects.using(db_alias).filter(key=meta_keys.PERIODICITY).order_by('-id') | ||
|
||
for metadata in periodicites: | ||
distribution = metadata.object_id | ||
if distribution in found_distributions: | ||
metadata.delete() | ||
|
||
found_distributions.add(distribution) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('management', '0006_auto_20190208_1509'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(delete_all_but_last_periodicity) | ||
] |