lots of changes
This commit is contained in:
@ -1,36 +1,38 @@
|
||||
from __future__ import with_statement
|
||||
import os
|
||||
import logging
|
||||
import importlib.util
|
||||
import glob
|
||||
import importlib
|
||||
|
||||
from alembic import context
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
from logging.config import fileConfig
|
||||
|
||||
from flask import current_app
|
||||
from app import db
|
||||
|
||||
# -----------------------------
|
||||
# 🔍 Automatically import all plugin models
|
||||
# 🔍 Automatically import all plugin models under their real package name
|
||||
# -----------------------------
|
||||
import glob
|
||||
import importlib.util
|
||||
|
||||
plugin_model_paths = glob.glob(os.path.join("plugins", "*", "models.py"))
|
||||
|
||||
for path in plugin_model_paths:
|
||||
module_name = path.replace("/", ".").replace(".py", "")
|
||||
# e.g. path = "plugins/plant/models.py"
|
||||
# We want to turn that into "plugins.plant.models"
|
||||
rel = path[len("plugins/") : -len("/models.py")] # e.g. "plant"
|
||||
pkg = f"plugins.{rel}.models" # e.g. "plugins.plant.models"
|
||||
try:
|
||||
spec = importlib.util.spec_from_file_location(module_name, path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
print(f"✅ Loaded: {module_name}")
|
||||
importlib.import_module(pkg)
|
||||
print(f"✅ Loaded: {pkg}")
|
||||
except Exception as e:
|
||||
print(f"❌ Failed to load {module_name}: {e}")
|
||||
print(f"❌ Failed to load {pkg}: {e}")
|
||||
# -----------------------------
|
||||
|
||||
config = context.config
|
||||
fileConfig(config.config_file_name)
|
||||
logger = logging.getLogger('alembic.env')
|
||||
logger = logging.getLogger("alembic.env")
|
||||
|
||||
# SQLAlchemy will look at this `target_metadata` when autogenerating
|
||||
target_metadata = db.metadata
|
||||
|
||||
def run_migrations_offline():
|
||||
|
Reference in New Issue
Block a user