From 2c78eddbeb427a668b7aaeb70c29cf1e1e99d1f9 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 27 Aug 2021 10:47:56 -0700 Subject: [PATCH] Normalize readthrough dates in advance of migration --- bookwyrm/migrations/0086_auto_20210827_1727.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bookwyrm/migrations/0086_auto_20210827_1727.py b/bookwyrm/migrations/0086_auto_20210827_1727.py index a9c9c7a8..7632a5b4 100644 --- a/bookwyrm/migrations/0086_auto_20210827_1727.py +++ b/bookwyrm/migrations/0086_auto_20210827_1727.py @@ -4,6 +4,18 @@ from django.db import migrations, models import django.db.models.expressions +def normalize_readthrough_dates(app_registry, schema_editor): + """bih""" + db_alias = schema_editor.connection.alias + app_registry.get_model("bookwyrm", "Readthrough").objects.using(db_alias).filter( + start_date__gt=models.F("finish_date") + ).update(start_date=models.F("finish_date")) + + +def reverse_func(apps, schema_editor): + """nothing to do here""" + + class Migration(migrations.Migration): dependencies = [ @@ -11,6 +23,7 @@ class Migration(migrations.Migration): ] operations = [ + migrations.RunPython(normalize_readthrough_dates, reverse_func), migrations.AlterModelOptions( name="readthrough", options={"ordering": ("-start_date",)},