From 25bb3a320aa26a0b077861774c81bd295a872334 Mon Sep 17 00:00:00 2001 From: Daniel Yohan Date: Mon, 21 Oct 2019 09:11:04 -0300 Subject: [PATCH] [fix] Migrations --- .../0032_repository_total_updates.py | 31 +++++++++++++++++++ .../migrations/0037_auto_20191011_2021.py | 16 +--------- 2 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 bothub/common/migrations/0032_repository_total_updates.py diff --git a/bothub/common/migrations/0032_repository_total_updates.py b/bothub/common/migrations/0032_repository_total_updates.py new file mode 100644 index 000000000..77b7f9aba --- /dev/null +++ b/bothub/common/migrations/0032_repository_total_updates.py @@ -0,0 +1,31 @@ +# Generated by Django 2.1.5 on 2019-08-14 19:45 + +from django.db import migrations, models + +from bothub.common.models import RepositoryUpdate +from bothub.common.models import Repository + + +def updateRepository(apps, schema_editor): + for update in RepositoryUpdate.objects.all().filter( + trained_at__isnull=False + ): + repository = Repository.objects.get(uuid=update.repository.uuid) + repository.total_updates += 1 + repository.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('common', '0031_auto_20190502_1732'), + ] + + operations = [ + migrations.AddField( + model_name='repository', + name='total_updates', + field=models.IntegerField(default=0, verbose_name='total updates'), + ), + migrations.RunPython(updateRepository), + ] diff --git a/bothub/common/migrations/0037_auto_20191011_2021.py b/bothub/common/migrations/0037_auto_20191011_2021.py index e43f6dbb0..49bdd9eec 100644 --- a/bothub/common/migrations/0037_auto_20191011_2021.py +++ b/bothub/common/migrations/0037_auto_20191011_2021.py @@ -5,14 +5,6 @@ from django.conf import settings from bothub.utils import send_bot_data_file_aws from bothub.common.models import RepositoryUpdate -from bothub.common.models import Repository - - -def updateRepository(apps, schema_editor): - for update in RepositoryUpdate.objects.all().filter(trained_at__isnull=False): - repository = Repository.objects.get(uuid=update.repository.uuid) - repository.total_updates += 1 - repository.save() def update_repository(apps, schema_editor): @@ -27,7 +19,7 @@ def update_repository(apps, schema_editor): class Migration(migrations.Migration): - dependencies = [("common", "0031_auto_20190502_1732")] + dependencies = [("common", "0032_repository_total_updates")] operations = [ migrations.RemoveField(model_name="repositoryvote", name="vote"), @@ -36,12 +28,6 @@ class Migration(migrations.Migration): name="nlp_server", field=models.URLField(blank=True, null=True, verbose_name="Base URL NLP"), ), - migrations.AddField( - model_name="repository", - name="total_updates", - field=models.IntegerField(default=0, verbose_name="total updates"), - ), - migrations.RunPython(updateRepository), migrations.AddField( model_name="repositoryvote", name="created",