Contains shared infrastructure for all coop services: - shared/ (factory, urls, user_loader, context, internal_api, jinja_setup) - models/ (User, Order, Calendar, Ticket, Product, Ghost CMS) - db/ (SQLAlchemy async session, base) - suma_browser/app/ (csrf, middleware, errors, authz, redis_cacher, payments, filters, utils) - suma_browser/templates/ (shared base layouts, macros, error pages) - static/ (CSS, JS, fonts, images) - alembic/ (database migrations) - config/ (app-config.yaml) - editor/ (Lexical editor Node.js build) - requirements.txt Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
62 lines
1.6 KiB
Python
62 lines
1.6 KiB
Python
from __future__ import annotations
|
|
import os, sys
|
|
from logging.config import fileConfig
|
|
from alembic import context
|
|
from sqlalchemy import engine_from_config, pool
|
|
|
|
config = context.config
|
|
|
|
if config.config_file_name is not None:
|
|
try:
|
|
fileConfig(config.config_file_name)
|
|
except Exception:
|
|
pass
|
|
|
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
|
|
|
from db.base import Base
|
|
import models # noqa: F401
|
|
|
|
target_metadata = Base.metadata
|
|
|
|
def _get_url() -> str:
|
|
url = os.getenv(
|
|
"ALEMBIC_DATABASE_URL",
|
|
os.getenv("DATABASE_URL", config.get_main_option("sqlalchemy.url") or "")
|
|
)
|
|
print(url)
|
|
return url
|
|
|
|
def run_migrations_offline() -> None:
|
|
url = _get_url()
|
|
context.configure(
|
|
url=url,
|
|
target_metadata=target_metadata,
|
|
literal_binds=True,
|
|
dialect_opts={"paramstyle": "named"},
|
|
compare_type=True,
|
|
)
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
def run_migrations_online() -> None:
|
|
url = _get_url()
|
|
if url:
|
|
config.set_main_option("sqlalchemy.url", url)
|
|
|
|
connectable = engine_from_config(
|
|
config.get_section(config.config_ini_section, {}),
|
|
prefix="sqlalchemy.",
|
|
poolclass=pool.NullPool,
|
|
)
|
|
|
|
with connectable.connect() as connection:
|
|
context.configure(connection=connection, target_metadata=target_metadata, compare_type=True)
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
if context.is_offline_mode():
|
|
run_migrations_offline()
|
|
else:
|
|
run_migrations_online()
|