fix(migrations): 删掉 fingerprint 的 GIN 索引——json 类型无 GIN 操作符类,建表必炸

fingerprint 列是 sa.JSON() → PG json 类型,GIN 只支持 jsonb,
CREATE INDEX ... USING GIN (fingerprint) 直接报 UndefinedObject。
且代码侧并无 JSON 包含查询(聚合过滤在 Python 侧,DB 走
stp_axis_status 复合索引),索引本身无用。

首次对生产库执行此迁移时因此报错、整个 upgrade 事务回滚
(2026-09-26)。已在本机修复后重新 upgrade head 成功。
未来若需 JSON 检索:先把列迁为 jsonb 再建 GIN。

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
2026-09-26 22:57:54 +08:00
parent f1d6a78f8a
commit 021bf311c1
@@ -70,12 +70,12 @@ def upgrade() -> None:
['stp_file_id', 'scheme_axis', 'feedback_status'], ['stp_file_id', 'scheme_axis', 'feedback_status'],
unique=False, unique=False,
) )
# GIN 索引(PG only):fingerprint JSON 字段 jsonb_path_query 类查询 # 注意:此处原本计划给 fingerprint 建 GIN 索引("jsonb_path_query 类查询"),
if op.get_bind().dialect.name == 'postgresql': # 但该列是 sa.JSON() → PG 的 json 类型,而 GIN 只支持 jsonb(json 无默认
op.execute( # 操作符类,CREATE INDEX 直接报 UndefinedObject)。且代码侧并无 JSON 包含
"CREATE INDEX ix_experience_feedback_fingerprint_gin " # 查询——聚合过滤在 Python 侧进行,DB 侧走上方 (stp_file_id, scheme_axis,
"ON experience_feedback USING GIN (fingerprint)" # feedback_status) 复合索引。故不建此索引;未来若真需要 JSON 检索,应先把
) # 列迁为 jsonb 再建 GIN。首次对生产库执行时曾因此报错回滚(2026-09-26)。
def downgrade() -> None: def downgrade() -> None: