Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion backend/app/core/base_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import UTC, datetime

from sqlalchemy import Boolean, DateTime, ForeignKey, Index, Integer, MetaData, String
from sqlalchemy import JSON, Boolean, DateTime, ForeignKey, Index, Integer, MetaData, String
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.ext.asyncio import AsyncAttrs
from sqlalchemy.orm import DeclarativeBase, Mapped, declared_attr, mapped_column, relationship

Expand All @@ -18,6 +19,12 @@
"pk": "pk_%(table_name)s",
}

# 跨方言 JSON 类型:PostgreSQL(生产)使用 JSONB,SQLite/MySQL(测试环境)降级为
# 通用 JSON,保证 create_all 与 autogenerate 在三种方言下均可渲染、零漂移。
# 各模块定义 JSON 列时统一使用 JSONType,而非直接硬编码 JSONB,避免破坏基类
# 「兼容 SQLite、MySQL 和 PostgreSQL」的承诺。
JSONType = JSONB().with_variant(JSON(), "sqlite", "mysql")


class MappedBase(AsyncAttrs, DeclarativeBase):
"""声明式基类
Expand Down
Loading