From b8e64056fbd571f75e3e31f21304f0e5d4c32bf7 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 29 Oct 2022 13:55:35 -0700 Subject: [PATCH] Fix 20_to_21 to not rely on current library code. Copy algorithm. --- utilities/database_upgrader.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/utilities/database_upgrader.py b/utilities/database_upgrader.py index 6232f71..db0e601 100644 --- a/utilities/database_upgrader.py +++ b/utilities/database_upgrader.py @@ -1,8 +1,9 @@ -import time import argparse import os +import shutil import sys +from voussoirkit import gentools from voussoirkit import vlogging import etiquette @@ -810,18 +811,19 @@ def upgrade_20_to_21(photodb): new_thumbnail.parent.makedirs(exist_ok=True) shutil.move(old_thumbnail.absolute_path, new_thumbnail.absolute_path) - photos = photodb.get_photos() - import shutil - for photo in photos: - if photo.thumbnail is None: - continue - old_thumbnail = photo.thumbnail - new_thumbnail = photo.make_thumbnail_filepath() + rows = photodb.select('SELECT id, thumbnail FROM photos where thumbnail IS NOT NULL') + for row in rows: + photo_id = row['id'] + chunked_id = [''.join(chunk) for chunk in gentools.chunk_generator(str(photo_id), 3)] + folder = chunked_id[:-1] + folder = os.sep.join(folder) + folder = photodb.thumbnail_directory.join(folder) + old_thumbnail = photodb.thumbnail_directory.join(row['thumbnail']) + new_thumbnail = folder.with_child(f'{photo_id}.jpg') print(old_thumbnail, new_thumbnail) photodb.on_commit_queue.append({'action': movethumbnail, 'args': (old_thumbnail, new_thumbnail)}) store_as = new_thumbnail.relative_to(photodb.thumbnail_directory) - photodb.update(table=etiquette.objects.Photo, pairs={'id': photo.id, 'thumbnail': store_as}, where_key='id') - photo.thumbnail = new_thumbnail + photodb.update(table=etiquette.objects.Photo, pairs={'id': photo_id, 'thumbnail': store_as}, where_key='id') def upgrade_21_to_22(photodb): m = Migrator(photodb)