From d305ec2dd39507deb9b162f871dd752b4c6ed681 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 25 May 2026 10:04:05 +0000 Subject: [PATCH] Skeleton for data migration --- .../migrations/0045_auto_20260525_0956.py | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/backend/InvenTree/common/migrations/0045_auto_20260525_0956.py diff --git a/src/backend/InvenTree/common/migrations/0045_auto_20260525_0956.py b/src/backend/InvenTree/common/migrations/0045_auto_20260525_0956.py new file mode 100644 index 0000000000..f7e5d6ee8e --- /dev/null +++ b/src/backend/InvenTree/common/migrations/0045_auto_20260525_0956.py @@ -0,0 +1,59 @@ +# Generated by Django 5.2.14 on 2026-05-25 09:56 + +from tqdm import tqdm + +from django.db import migrations + + +def migrate_notes(apps, schema_editor): + """Migrate existing notes to the new Note model.""" + + # New target models + Note = apps.get_model('common', 'Note') + NotesImage = apps.get_model('common', 'NotesImage') + + for app, model in [ + ('build', 'Build'), + ('company', 'Company'), + ('company', 'ManufacturerPart'), + ('company', 'SupplierPart'), + ('order', 'PurchaseOrder'), + ('order', 'ReturnOrder'), + ('order', 'SalesOrder'), + ('order', 'TransferOrder'), + ('part', 'Part'), + ('stock', 'StockItem'), + ]: + # Find old model which contains the 'notes' field + OldModel = apps.get_model(app, model) + with_notes = OldModel.objects.exclude(notes__isnull=True).exclude(notes='') + + if not with_notes.exists(): + continue + + progress = tqdm(total=with_notes.count(), desc=f'Migrating notes for {app}.{model}') + + for obj in with_notes: + # TODO ... + + progress.update(1) + + +class Migration(migrations.Migration): + + # Ensure that each app which supports 'notes' is up-to-date first + dependencies = [ + ("build", "0058_buildline_consumed"), + ("common", "0044_note"), + ("company", "0079_auto_20260212_1054"), + ("order", "0119_transferorderlineitem_line_int"), + ("part", "0150_part_maximum_stock"), + ("stock", "0119_alter_stockitemtestresult_date") + ] + + operations = [ + migrations.RunPython( + code=migrate_notes, + reverse_code=migrations.RunPython.noop, + ) + ]