From f8c53e91ad8ff96a50665248f2588f162578c06d Mon Sep 17 00:00:00 2001 From: jessikitty Date: Mon, 12 Oct 2026 21:29:32 +1100 Subject: [PATCH] Add parts catalogue migration script --- migrate_add_parts_catalogue.py | 52 ++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 migrate_add_parts_catalogue.py diff --git a/migrate_add_parts_catalogue.py b/migrate_add_parts_catalogue.py new file mode 100644 index 0000000..408afe9 --- /dev/null +++ b/migrate_add_parts_catalogue.py @@ -0,0 +1,52 @@ +""" +Migration: local parts catalogue and tape printing. + +Creates part_catalog_categories, part_catalog_items and part_catalog_syncs. +Safe to run more than once - every step checks first. + + python migrate_add_parts_catalogue.py + +You do not strictly need this: app/services/schema_upgrade.py creates all +three at boot. It exists so you can make the database change deliberately, +and see what it did, before restarting the service. + +It does NOT download the catalogue. Press "Update catalogue" on +/admin/labels/catalog once LIM is running - that fetches about 60,000 parts +from Rebrickable in the background. + +Created by: Jess Rogerson (yelling commands at Claude.AI) +""" + +import os +import sys + +from sqlalchemy import inspect + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) + +from app import create_app, db # noqa: E402 +from app.models.part_catalog_item import (CatalogSync, # noqa: E402 + PartCatalogCategory, + PartCatalogItem) + + +def main(): + app = create_app(os.environ.get('FLASK_CONFIG', 'default')) + + with app.app_context(): + existing = set(inspect(db.engine).get_table_names()) + + for model in (PartCatalogCategory, PartCatalogItem, CatalogSync): + if model.__tablename__ in existing: + print(f' = table {model.__tablename__} already present') + else: + model.__table__.create(db.engine, checkfirst=True) + print(f' + created table {model.__tablename__}') + + print(f'\n catalogue rows: {PartCatalogItem.query.count():,}') + print('\nDone.') + print('Next: open /admin/labels/catalog and press "Update catalogue".') + + +if __name__ == '__main__': + main()