X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/82c3054bcdeb000aa9782da80d644070797b5cbe..ae60b2a3949e96357477cc04f90fd0873cee8a92:/apps/catalogue/migrations/0003_populate_ancestors.py diff --git a/apps/catalogue/migrations/0003_populate_ancestors.py b/apps/catalogue/migrations/0003_populate_ancestors.py deleted file mode 100644 index b6117570b..000000000 --- a/apps/catalogue/migrations/0003_populate_ancestors.py +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import migrations - - -def populate_ancestors(apps, schema_editor): - """Fixes the ancestry cache.""" - # TODO: table names - from django.db import connection, transaction - if connection.vendor == 'postgres': - cursor = connection.cursor() - cursor.execute(""" - WITH RECURSIVE ancestry AS ( - SELECT book.id, book.parent_id - FROM catalogue_book AS book - WHERE book.parent_id IS NOT NULL - UNION - SELECT ancestor.id, book.parent_id - FROM ancestry AS ancestor, catalogue_book AS book - WHERE ancestor.parent_id = book.id - AND book.parent_id IS NOT NULL - ) - INSERT INTO catalogue_book_ancestor - (from_book_id, to_book_id) - SELECT id, parent_id - FROM ancestry - ORDER BY id; - """) - else: - Book = apps.get_model("catalogue", "Book") - for book in Book.objects.exclude(parent=None): - parent = book.parent - while parent is not None: - book.ancestor.add(parent) - parent = parent.parent - - -def remove_book_tags(apps, schema_editor): - Tag = apps.get_model("catalogue", "Tag") - Book = apps.get_model("catalogue", "Book") - Tag.objects.filter(category='book').delete() - - -class Migration(migrations.Migration): - - dependencies = [ - ('catalogue', '0002_book_ancestor'), - ] - - operations = [ - migrations.RunPython(populate_ancestors), - migrations.RunPython(remove_book_tags), - ]