table follow requires the id length of user

This commit is contained in:
2026-05-18 22:36:23 +08:00
parent a73b3cce26
commit d457c07f40
2 changed files with 23 additions and 3 deletions
+6 -1
View File
@@ -60,6 +60,11 @@ class AutoID:
_id_prefix_len = 3 # 前缀长度
_id_payload_len = 22 # 主体长度(ULID 转 Base62 最大约 22 位)
@classmethod
def id_length(cls) -> int:
"""返回当前类 ID 的总长度"""
return cls._id_prefix_len + cls._id_payload_len
@declared_attr
def id(cls):
# 运行时动态获取子类的 __tablename__
@@ -74,4 +79,4 @@ class AutoID:
payload = gen_convex_payload(length=s_len)
return f"{prefix}{payload}"
return Column(String(p_len + s_len), primary_key=True, default=id_factory)
return Column(String(cls.id_length()), primary_key=True, default=id_factory)