Skip to content

Commit

Permalink
Agrego migración de borrado de periodicities duplicadas
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaslavandeira committed Feb 26, 2019
1 parent ad96521 commit ecd19dd
Showing 1 changed file with 33 additions and 0 deletions.
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)
]

0 comments on commit ecd19dd

Please sign in to comment.