diff --git a/catalog/book/models.py b/catalog/book/models.py index cc91a58a..52e19f89 100644 --- a/catalog/book/models.py +++ b/catalog/book/models.py @@ -271,7 +271,7 @@ class Edition(Item): def delete(self, using=None, keep_parents=False, soft=True, *args, **kwargs): if soft: self.works.clear() - return super().delete(using, soft, keep_parents, *args, **kwargs) + return super().delete(using, keep_parents, soft, *args, **kwargs) def update_linked_items_from_external_resource(self, resource): """add Work from resource.metadata['work'] if not yet""" diff --git a/catalog/common/migrations.py b/catalog/common/migrations.py new file mode 100644 index 00000000..b18407ea --- /dev/null +++ b/catalog/common/migrations.py @@ -0,0 +1,16 @@ +from django.db import connection +from loguru import logger + + +def fix_20250208(): + logger.warning("Fixing soft-deleted editions...") + with connection.cursor() as cursor: + cursor.execute(""" + UPDATE catalog_item + SET is_deleted = true + WHERE id NOT IN ( SELECT item_ptr_id FROM catalog_edition ) AND polymorphic_ctype_id = (SELECT id FROM django_content_type WHERE app_label='catalog' AND model='edition'); + INSERT INTO catalog_edition (item_ptr_id) + SELECT id FROM catalog_item + WHERE id NOT IN ( SELECT item_ptr_id FROM catalog_edition ) AND polymorphic_ctype_id = (SELECT id FROM django_content_type WHERE app_label='catalog' AND model='edition'); + """) + logger.warning("Fix complete.") diff --git a/catalog/jobs/discover.py b/catalog/jobs/discover.py index f0f0d275..ba6fa5f1 100644 --- a/catalog/jobs/discover.py +++ b/catalog/jobs/discover.py @@ -111,6 +111,7 @@ class DiscoverGenerator(BaseJob): ) item_ids = extra_ids + item_ids items = [Item.objects.get(pk=i) for i in item_ids] + items = [i for i in items if not i.is_deleted and not i.merged_to_item_id] if category == ItemCategory.TV: items = self.cleanup_shows(items) key = "trending_" + category.value diff --git a/catalog/migrations/0002_fix_soft_deleted_edition.py b/catalog/migrations/0002_fix_soft_deleted_edition.py new file mode 100644 index 00000000..460abb26 --- /dev/null +++ b/catalog/migrations/0002_fix_soft_deleted_edition.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.18 on 2025-02-09 02:40 + +import django_rq +from django.db import migrations + +from catalog.common.migrations import fix_20250208 + + +# this is a fix for a bug introduced in 0.10 +# safe to be excluded in squashed migration in future +def fix_soft_deleted_edition(apps, schema_editor): + django_rq.get_queue("mastodon").enqueue(fix_20250208) + print("(Queued)", end="") + + +class Migration(migrations.Migration): + dependencies = [ + ("catalog", "0001_initial_0_10"), + ] + + operations = [ + migrations.RunPython(fix_soft_deleted_edition), + ] diff --git a/journal/migrations/0005_csvexporter.py b/journal/migrations/0005_csvexporter.py index d4ba46f2..e6061604 100644 --- a/journal/migrations/0005_csvexporter.py +++ b/journal/migrations/0005_csvexporter.py @@ -20,4 +20,14 @@ class Migration(migrations.Migration): }, bases=("users.task",), ), + migrations.CreateModel( + name="NdjsonExporter", + fields=[], + options={ + "proxy": True, + "indexes": [], + "constraints": [], + }, + bases=("users.task",), + ), ] diff --git a/users/migrations/0007_alter_task_type.py b/users/migrations/0007_alter_task_type.py index 0bb78ec2..d949ec14 100644 --- a/users/migrations/0007_alter_task_type.py +++ b/users/migrations/0007_alter_task_type.py @@ -19,6 +19,7 @@ class Migration(migrations.Migration): ("journal.doufenexporter", "doufen exporter"), ("journal.goodreadsimporter", "goodreads importer"), ("journal.letterboxdimporter", "letterboxd importer"), + ("journal.ndjsonexporter", "ndjson exporter"), ], db_index=True, max_length=255,