Add parts catalogue migration script
This commit is contained in:
1 parent
60f83fc002
commit
f8c53e91ad
1 file changed
+52
@@ -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()
|
||||
Reference in new issue
Block a user