mirror of
https://github.com/escalante29/WealthySmart.git
synced 2026-05-19 10:08:48 +02:00
All checks were successful
Deploy to VPS / deploy (push) Successful in 50s
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
36 lines
918 B
Python
36 lines
918 B
Python
from sqlalchemy import text
|
|
from sqlmodel import SQLModel, Session, create_engine
|
|
|
|
from app.config import settings
|
|
|
|
engine = create_engine(settings.DATABASE_URL)
|
|
|
|
|
|
def init_db():
|
|
SQLModel.metadata.create_all(engine)
|
|
|
|
|
|
def run_migrations():
|
|
"""Run idempotent schema migrations for columns added after initial create."""
|
|
with engine.connect() as conn:
|
|
try:
|
|
conn.execute(
|
|
text(
|
|
"ALTER TABLE transaction ADD COLUMN IF NOT EXISTS deferred_to_next_cycle BOOLEAN NOT NULL DEFAULT false"
|
|
)
|
|
)
|
|
conn.commit()
|
|
except Exception:
|
|
conn.rollback()
|
|
|
|
try:
|
|
conn.execute(text("ALTER TYPE currency ADD VALUE IF NOT EXISTS 'EUR'"))
|
|
conn.commit()
|
|
except Exception:
|
|
conn.rollback()
|
|
|
|
|
|
def get_session():
|
|
with Session(engine) as session:
|
|
yield session
|