Fix alembic migration module import error
- Fixed Python import path in alembic/env.py - Added settings import to ensure consistent database URL - Synchronized database configuration between app and alembic generated with BackendIM... (backend.im)
This commit is contained in:
parent
d20c3af0bc
commit
b315ed6c34
@ -1,10 +1,17 @@
|
||||
from logging.config import fileConfig
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from sqlalchemy import engine_from_config
|
||||
from sqlalchemy import pool
|
||||
|
||||
from alembic import context
|
||||
|
||||
# Add the project root directory to Python's module search path
|
||||
project_root = Path(__file__).parent.parent.absolute()
|
||||
sys.path.append(str(project_root))
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
config = context.config
|
||||
@ -13,6 +20,10 @@ config = context.config
|
||||
# This line sets up loggers basically.
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
# Import settings and set alembic's sqlalchemy.url to match the app's settings
|
||||
from app.core.config import settings
|
||||
config.set_main_option('sqlalchemy.url', settings.DATABASE_URL)
|
||||
|
||||
# add your model's MetaData object here
|
||||
# for 'autogenerate' support
|
||||
# from myapp import mymodel
|
||||
|
@ -20,7 +20,7 @@ class Settings(BaseSettings):
|
||||
env_file = ".env"
|
||||
env_file_encoding = "utf-8"
|
||||
|
||||
# Ensure DB directory exists
|
||||
Path(settings.DB_DIR).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
settings = Settings()
|
||||
|
||||
# Ensure DB directory exists
|
||||
settings.DB_DIR.mkdir(parents=True, exist_ok=True)
|
Loading…
x
Reference in New Issue
Block a user