File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 22import os
33import sys
44from logging .config import fileConfig
5+ import importlib
6+ from pathlib import Path
57
68# Add the project root directory to the Python path
79sys .path .insert (0 , os .path .abspath (os .path .join (os .path .dirname (__file__ ), ".." )))
1214
1315from alembic import context
1416from api .core .config import settings
15-
16- # Import your models here
1717from api .core .database import Base
1818
19+ # Automatically import all models
20+ src_path = Path (__file__ ).parent .parent / "api" / "src"
21+ for path in src_path .rglob ("*.py" ):
22+ if path .name != "__init__.py" :
23+ module_path = str (path .relative_to (Path (__file__ ).parent .parent )).replace (os .sep , "." )[:- 3 ]
24+ try :
25+ importlib .import_module (module_path )
26+ except Exception as e :
27+ print (f"Failed to import { module_path } : { e } " )
28+
1929# this is the Alembic Config object
2030config = context .config
2131
You can’t perform that action at this time.
0 commit comments