feat(usercenter): M0 多 provider 身份表 user_identities + 幂等回填 - #43
Merged
Conversation
RFC involutionhell-backend#42 / ADR-001 的第一阶段,纯增量零行为变化: - user_identities 表:UNIQUE(provider,provider_user_id) + UNIQUE(user_id,provider) + provider 小写 CHECK + FK ON DELETE CASCADE - 启动回填存量 github_id → provider='github' 行,ON CONFLICT DO NOTHING 保幂等 - UserIdentity model + JdbcUserIdentityRepository(沿用 JDBC 惯例) - 5 个仓库测试覆盖两条 UNIQUE、级联删除、回填幂等 - ADR-001(OKF frontmatter)记录设计决策与 OAuth state 防护协议 生产数据干跑验证:51 个 github_id 账号,0 重复 / 0 非数字 cast,回填无冲突。 全量 251 测试通过。
longsizhuo
force-pushed
the
feat/user-identities-m0
branch
from
July 19, 2026 00:04
a68f966 to
9e91771
Compare
xhigh review (PR #43) 的已确认问题: - init.sql 补 user_identities 表:三处 schema 同步惯例(INV-004 教训), 否则 docker-compose 起的库缺表,M1 登录 500 - ADR 的 state 不变量 INV-006 → INV-007:INV-006 已被 PR #41 限流占用 - 回填注释澄清边界:依赖 SPRING_SQL_INIT_MODE=always;只治行缺失不治值变化; M2 解绑 github 须同时清 github_id 列,否则重启静默复活已撤销绑定 - 仓库层 provider 归一化小写:JustAuth source 名大写,不归一化查询侧静默查空 - insert() javadoc 声明忽略 linkedAt/lastLoginAt(由 DB default 生成) - 幂等测试改从 classpath 的 schema.sql 机械提取回填语句,不再手抄副本 全量 252 测试通过。
M0 的 user_identities 回填读 user_accounts.github_id,但 docker/init-db/init.sql 建的 user_accounts 只有 7 列、缺 github_id/avatar_url/email/preferences,schema.sql 的 CREATE TABLE IF NOT EXISTS 又补不上已存在表的列——全新 docker 卷首启时回填 直接 column "github_id" does not exist 崩,后端起不来(既有 bug:github 登录 INSERT 本就缺列,M0 把它升级成硬崩)。 - init.sql 的 user_accounts 补齐到与 schema.sql 一致 - .env.example / application.properties 去掉"改成 never"的误导建议:schema.sql 幂等,always 是安全默认;改 never 会让后续新增表在本地缺失(曾踩坑) - README 加建表两路径说明 + 缺表/缺列排查(down -v 重建卷) 验证:一次性 throwaway 容器跑 init.sql→schema.sql 两遍 exit=0、无缺列崩溃、 user_identities 建成且幂等。全量 252 测试通过。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RFC #42 / ADR-001 的第一阶段。纯增量、零行为变化——只加一张表和幂等回填,不 touch 任何既有代码路径或数据行。
改动
user_identities表(schema.sql):UNIQUE(provider, provider_user_id)(一个第三方身份只绑一个账号)+UNIQUE(user_id, provider)(同账号同 provider 至多一个身份)+CHECK(provider=lower(provider))+ FKON DELETE CASCADE。INSERT ... SELECT ... WHERE github_id IS NOT NULL ON CONFLICT DO NOTHING——schema.sql 每次启动执行,无冲突目标保证幂等,顺带补齐未来双写期漂移。UserIdentitymodel +JdbcUserIdentityRepository:沿用现有 JDBC 仓库惯例(RowMapper / GeneratedKeyHolder /toInstant)。docs/wiki/adr/001-multi-provider-identity.md:OKF frontmatter 格式的 ADR,记录表设计、约束语义的 why、OAuth state/绑定防护协议、库选型(留 JustAuth)、M0-M4 迁移阶段。验证
involution-pg-backup日备(@daily)保留 30 天 + 8 周 + 12 月,M0 上线有回滚兜底。部署注意
后端重启带新 schema 时自动建表 + 回填,无需手动迁移。
github_id列保留(M1-M3 双写),M4 才删。后续(本 PR 不含)
M1
loginByProvider统一流程 + OAuth state/cookie 硬化 + 新增安全不变量 INV-006(callback 不得信任 state 中的用户身份)。Closes #42 的 M0 阶段。
🤖 Generated with Claude Code
https://claude.ai/code/session_01RtSNVtrEkCsFVHrbt4Zjgi