feat: update default system value in AuditLog model for consistency

This commit is contained in:
2026-02-19 17:51:50 -06:00
parent dc37f458f5
commit e1ce41f9f9
3 changed files with 24 additions and 189 deletions

View File

@@ -80,33 +80,36 @@ target_metadata = Base.metadata
def import_models_from_dir(dir_path: str):
"""Importa recursivamente cualquier archivo models.py desde dir_path y archivos en directorios models/"""
import sys
def _load_module(module_path: str):
rel_path = os.path.relpath(module_path, BASE_DIR)
module_name = rel_path.replace(os.sep, ".").replace(".py", "")
# Skip if already loaded to avoid duplicate SQLAlchemy table registrations
if module_name in sys.modules:
return
spec = importlib.util.spec_from_file_location(module_name, module_path)
mod = importlib.util.module_from_spec(spec)
# Register in sys.modules before exec so transitive imports resolve correctly
sys.modules[module_name] = mod
spec.loader.exec_module(mod)
for root, dirs, files in os.walk(dir_path):
# Importar archivos models.py directos
if "models.py" in files:
module_path = os.path.join(root, "models.py")
# Convertir path en nombre de módulo compatible
rel_path = os.path.relpath(module_path, BASE_DIR)
module_name = rel_path.replace(os.sep, ".").replace(".py", "")
# Lazy import
spec = importlib.util.spec_from_file_location(module_name, module_path)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
try:
_load_module(os.path.join(root, "models.py"))
except Exception as e:
logger.warning(f"No se pudo importar {os.path.join(root, 'models.py')}: {e}")
# Importar todos los archivos .py en directorios llamados "models"
if os.path.basename(root) == "models":
for file in files:
if file.endswith(".py") and not file.startswith("__"):
module_path = os.path.join(root, file)
rel_path = os.path.relpath(module_path, BASE_DIR)
module_name = rel_path.replace(os.sep, ".").replace(".py", "")
try:
spec = importlib.util.spec_from_file_location(
module_name, module_path
)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
_load_module(os.path.join(root, file))
except Exception as e:
logger.warning(f"No se pudo importar {module_path}: {e}")
logger.warning(f"No se pudo importar {os.path.join(root, file)}: {e}")
# Importar todos los models dentro de api/v1/modules y api/v1/modules/uploads