Skeleton for data migration

This commit is contained in:
Oliver Walters 2026-05-25 10:04:05 +00:00
parent 8f36287d12
commit d305ec2dd3
1 changed files with 59 additions and 0 deletions

View File

@ -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,
)
]