commit inicial
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
from sqlalchemy import create_engine, text
|
||||
from sqlalchemy.orm import sessionmaker, DeclarativeBase
|
||||
from app.config import settings
|
||||
|
||||
engine = create_engine(
|
||||
settings.DATABASE_URL,
|
||||
connect_args={"check_same_thread": False},
|
||||
)
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
|
||||
def get_db():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def apply_migrations():
|
||||
"""Aplica migraciones incrementales compatibles con SQLite."""
|
||||
with engine.connect() as conn:
|
||||
for sql in [
|
||||
"ALTER TABLE playlists ADD COLUMN spotify_type VARCHAR NOT NULL DEFAULT 'playlist'",
|
||||
"ALTER TABLE playlists ADD COLUMN emoji VARCHAR NOT NULL DEFAULT ''",
|
||||
]:
|
||||
try:
|
||||
conn.execute(text(sql))
|
||||
conn.commit()
|
||||
except Exception:
|
||||
pass # columna ya existe
|
||||
Reference in New Issue
Block a user