yabeskn's picture
fix: change EXPOSE and uvicorn port from 8080 to 7860 in Dockerfile
b613c13
Raw History Blame Contribute Delete
1.17 kB
"""Single shared SQLAlchemy declarative Base for all Brigawan models.
All model modules should import Base from here to ensure Alembic
and cross-table relationships work correctly.
Also provides renderable JSONB type for SQLite dev compatibility.
"""
from sqlalchemy import TypeDecorator, Text
from sqlalchemy.dialects.postgresql import JSONB as PGJSONB
from sqlalchemy.orm import declarative_base
import json
class JSONB(TypeDecorator):
"""Cross-dialect JSONB type.
Uses native JSONB on PostgreSQL, falls back to JSON text on SQLite.
"""
impl = Text
cache_ok = True
def load_dialect_impl(self, dialect):
if dialect.name == "postgresql":
return dialect.type_descriptor(PGJSONB())
return dialect.type_descriptor(Text())
def process_bind_param(self, value, dialect):
if dialect.name == "postgresql":
return value
return json.dumps(value) if value is not None else None
def process_result_value(self, value, dialect):
if dialect.name == "postgresql":
return value
return json.loads(value) if value is not None else None
Base = declarative_base()