2021-08-27 17:31:39 +00:00
|
|
|
# Generated by Django 3.2.4 on 2021-08-27 17:27
|
2021-08-11 18:19:06 +00:00
|
|
|
|
|
|
|
from django.db import migrations, models
|
|
|
|
import django.db.models.expressions
|
|
|
|
|
|
|
|
|
2021-08-27 17:47:56 +00:00
|
|
|
def normalize_readthrough_dates(app_registry, schema_editor):
|
2021-08-29 18:12:57 +00:00
|
|
|
"""Find any invalid dates and reset them"""
|
2021-08-27 17:47:56 +00:00
|
|
|
db_alias = schema_editor.connection.alias
|
2021-08-29 18:12:57 +00:00
|
|
|
app_registry.get_model("bookwyrm", "ReadThrough").objects.using(db_alias).filter(
|
2021-08-27 17:47:56 +00:00
|
|
|
start_date__gt=models.F("finish_date")
|
|
|
|
).update(start_date=models.F("finish_date"))
|
|
|
|
|
|
|
|
|
|
|
|
def reverse_func(apps, schema_editor):
|
|
|
|
"""nothing to do here"""
|
|
|
|
|
|
|
|
|
2021-08-11 18:19:06 +00:00
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
2021-08-27 17:31:39 +00:00
|
|
|
("bookwyrm", "0085_user_saved_lists"),
|
2021-08-11 18:19:06 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
2021-08-27 17:47:56 +00:00
|
|
|
migrations.RunPython(normalize_readthrough_dates, reverse_func),
|
2021-08-11 18:19:06 +00:00
|
|
|
migrations.AlterModelOptions(
|
|
|
|
name="readthrough",
|
|
|
|
options={"ordering": ("-start_date",)},
|
|
|
|
),
|
|
|
|
migrations.AddConstraint(
|
|
|
|
model_name="readthrough",
|
|
|
|
constraint=models.CheckConstraint(
|
|
|
|
check=models.Q(
|
|
|
|
("finish_date__gte", django.db.models.expressions.F("start_date"))
|
|
|
|
),
|
|
|
|
name="chronology",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]
|