basic profile
This commit is contained in:
45
packages/backend/alembic/env.py
Normal file
45
packages/backend/alembic/env.py
Normal file
@@ -0,0 +1,45 @@
|
||||
# packages/backend/alembic/env.py
|
||||
|
||||
import os
|
||||
import sys
|
||||
from logging.config import fileConfig
|
||||
|
||||
from dotenv import load_dotenv # <--- 1. AGGIUNGI QUESTO IMPORT
|
||||
|
||||
from sqlalchemy import engine_from_config
|
||||
from sqlalchemy import pool
|
||||
|
||||
from alembic import context
|
||||
|
||||
# Aggiungi la root del progetto (/app) al percorso di ricerca di Python
|
||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||
|
||||
# Aggiungi l'import del tuo modello specifico sotto l'import di Base
|
||||
from app.models import Base, Celebrity
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
config = context.config
|
||||
|
||||
# === 2. AGGIUNGI QUESTA SEZIONE PER CARICARE LA VARIABILE D'AMBIENTE ===
|
||||
# Carica il file .env che si trova nella root del progetto (/app)
|
||||
# Dato che lo script è in /app/alembic, dobbiamo risalire di un livello
|
||||
dotenv_path = os.path.join(os.path.dirname(__file__), '..', '.env')
|
||||
load_dotenv(dotenv_path=dotenv_path)
|
||||
|
||||
# Imposta programmaticamente l'URL del database nell'oggetto di configurazione di Alembic
|
||||
config.set_main_option('sqlalchemy.url', os.getenv('DATABASE_URL'))
|
||||
# === FINE DELLA SEZIONE DA AGGIUNGERE ===
|
||||
|
||||
# Interpret the config file for Python logging.
|
||||
# This line sets up loggers basically.
|
||||
if config.config_file_name is not None:
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
# add your model's MetaData object here
|
||||
# for 'autogenerate' support
|
||||
# from myapp import mymodel
|
||||
# target_metadata = mymodel.Base.metadata
|
||||
target_metadata = Base.metadata
|
||||
|
||||
# ... il resto del file rimane invariato ...
|
||||
Reference in New Issue
Block a user