Enthält ~18 Commits vom Nextcloud-Mount (FUSE-Blocker verhinderte direkten Push): Excel-Export-Fix, IMAP-Verbesserungen, Scan-Fixes, UI-Updates. Aus Forgejo-Migration squashed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
63 lines
1.6 KiB
Python
63 lines
1.6 KiB
Python
"""Alembic Environment Configuration"""
|
|
from logging.config import fileConfig
|
|
|
|
from sqlalchemy import pool
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
|
|
|
from alembic import context
|
|
|
|
# Import models from the actual application
|
|
import sys
|
|
import os
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from backend.models import Base, Invoice, EmailLog, InvoiceDetail, User
|
|
|
|
# Set target metadata for autogenerate
|
|
target_metadata = Base.metadata
|
|
|
|
# other values from the config
|
|
def get_url():
|
|
"""Get database URL from environment"""
|
|
return os.getenv("DATABASE_URL", "postgresql+psycopg2://postgres:postgres@localhost:5432/invoice_check")
|
|
|
|
def run_migrations_offline() -> None:
|
|
"""Run migrations in 'offline' mode."""
|
|
url = get_url()
|
|
context.configure(
|
|
url=url,
|
|
target_metadata=target_metadata,
|
|
literal_binds=True,
|
|
dialect_opts={"paramstyle": "named"},
|
|
render_as_batch=True,
|
|
)
|
|
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
def run_migrations_online() -> None:
|
|
"""Run migrations in 'online' mode."""
|
|
url = get_url()
|
|
|
|
connectable = create_engine(
|
|
url,
|
|
poolclass=pool.NullPool,
|
|
)
|
|
|
|
with connectable.connect() as connection:
|
|
context.configure(
|
|
connection=connection,
|
|
target_metadata=target_metadata,
|
|
render_as_batch=True,
|
|
)
|
|
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
if context.is_offline_mode():
|
|
run_migrations_offline()
|
|
else:
|
|
run_migrations_online()
|