mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-03-13 09:10:12 +00:00
Add naming_convention to Base.metadata so Alembic batch-mode reflection can match unnamed FK constraints created by migration 0002. Pass naming_convention and render_as_batch=True through env.py online config. Add migration roundtrip tests (upgrade/downgrade/cycle from baseline). Amp-Thread-ID: https://ampcode.com/threads/T-019ce466-1683-7471-b6e1-bb078223cda0 Co-authored-by: Amp <amp@ampcode.com>
31 lines
932 B
Python
31 lines
932 B
Python
from typing import Any
|
|
from datetime import datetime
|
|
from sqlalchemy import MetaData
|
|
from sqlalchemy.orm import DeclarativeBase
|
|
|
|
NAMING_CONVENTION = {
|
|
"ix": "ix_%(table_name)s_%(column_0_N_name)s",
|
|
"uq": "uq_%(table_name)s_%(column_0_N_name)s",
|
|
"ck": "ck_%(table_name)s_%(constraint_name)s",
|
|
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
|
|
"pk": "pk_%(table_name)s",
|
|
}
|
|
|
|
class Base(DeclarativeBase):
|
|
metadata = MetaData(naming_convention=NAMING_CONVENTION)
|
|
|
|
def to_dict(obj: Any, include_none: bool = False) -> dict[str, Any]:
|
|
fields = obj.__table__.columns.keys()
|
|
out: dict[str, Any] = {}
|
|
for field in fields:
|
|
val = getattr(obj, field)
|
|
if val is None and not include_none:
|
|
continue
|
|
if isinstance(val, datetime):
|
|
out[field] = val.isoformat()
|
|
else:
|
|
out[field] = val
|
|
return out
|
|
|
|
# TODO: Define models here
|