File indexing completed on 2026-07-21 08:46:24
0001
0002 """Generate the database schema DBML to stdout.
0003
0004 Wraps django-dbml's management command with a workaround: the library
0005 (1.1.2) looks index fields up verbatim, so an index declared with a
0006 descending field ('-timestamp_created') raises KeyError. The ordering
0007 prefix is stripped from every model index before generation — the
0008 diagram loses only the sort direction.
0009
0010 Usage: python scripts/generate-schema-dbml.py > testbed-schema.dbml
0011 (the workflow also strips the generator's Last-Updated timestamp line
0012 so an unchanged schema produces no diff).
0013 """
0014 import os
0015 import sys
0016
0017 THIS_DIR = os.path.dirname(os.path.abspath(__file__))
0018 sys.path.insert(0, os.path.join(THIS_DIR, '..', 'src'))
0019 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'swf_monitor_project.settings')
0020
0021 import django
0022 django.setup()
0023
0024 from django.apps import apps
0025 from django.core.management import call_command
0026
0027 for model in apps.get_models():
0028 for index in model._meta.indexes:
0029 index.fields = [f.lstrip('-') for f in index.fields]
0030
0031 call_command('dbml')