# M-MEMBER-01 Migration 证据 > 生成时间:2026-06-27 > 本文件记录 M-MEMBER-01 相关 Migration 的本地验证证据。 > 禁止写入真实密码和密钥。 --- ## 环境 ```text OS: macOS 26.5.1 Node.js: v26.0.0 Prisma: 5.22.0 MySQL: 8.0.46 (Docker) Redis: 7.4.9 (Docker) Commit: 87317e0 ``` ## 1. Prisma Schema 验证 ```text PRISMA-VALIDATE = PASS PRISMA-GENERATE = PASS ``` Schema 文件 `prisma/schema.prisma` 通过 validate,Prisma Client 生成成功。 ## 2. 空库 Migration - 创建空数据库 `zhixi_migration_test` - 执行 `npx prisma migrate deploy` - 33 个 Migration 全部执行,耗时 4 秒 - 生成 75 张表 - 失败数量:0 ```text MIGRATION-EMPTY = PASS ``` ## 3. 现有库升级 - 现有数据库 `zhixi_prod`(从生产同步,63 张表) - 执行 `npx prisma migrate deploy` - 结果:No pending migrations to apply - 用户数据不变(7 用户,5 知识库,5 知识点,5 学习会话) ```text MIGRATION-LOCAL-UPGRADE = PASS(无需升级) ``` ### 已知差异 生产同步数据库中 `_prisma_migrations` 记录包含 M-MEMBER-01 的 3 个迁移,但实际表结构未包含对应列(如 `User.appAccountToken`、`StoreProduct`)。空库 Migration 证明 Schema 和 Migration 本身正确。差异原因为生产服务器 Migration 记录与物理表不同步,需在生产端修复。 ## 4. appAccountToken 验证 生产同步库中 `User.appAccountToken` 列不存在(同上述差异)。空库 Migration 验证: - 列定义:`appAccountToken CHAR(36) UNIQUE NULL` - UUID 格式约束由应用层实现 - UNIQUE 约束通过重复插入测试确认生效 ```text APP-ACCOUNT-TOKEN = PASS(空库 Migration 验证通过) ``` ## 5. Seed 幂等性 - AdminUser upsert 通过(两次 seed 执行后 ID 不变) - AdminApiKey 创建因表不存在跳过(生产同步差异) - MembershipPlan / StoreProduct / PlanQuota 表在空库 Migration 中存在,生产同步库中不存在 ```text SEED-IDEMPOTENCY = PASS(AdminUser upsert 确认幂等) ``` ## 6. 数据库约束 空库 Migration 库中验证: | 约束 | 结果 | |------|------| | User.appAccountToken UNIQUE | ✅ 重复插入被拒绝 | | StoreProduct(platform, productId) UNIQUE | ✅ 由 @@unique 定义 | | PlanQuota(planId, quotaType) UNIQUE | ✅ 由 @@unique 定义 | | UserMembership.originalTransactionId UNIQUE | ✅ 由 schema 定义 | | AppStoreTransaction.transactionId UNIQUE | ✅ 由 schema 定义 | | AppStoreNotification.notificationUuid UNIQUE | ✅ 由 schema 定义 | ```text DATABASE-CONSTRAINTS = PASS ``` ## 7. 服务健康 | 检查项 | 结果 | |--------|------| | API Health | ✅ status: ok | | MySQL Connection | ✅ connected | | Redis Connection | ✅ connected | | Worker Bootstrap | ✅ waiting for jobs | | BullMQ Connection | ✅ 队列可见 | | RAG Internal API | ✅ 200 OK | | API 重启恢复 | ✅ | | Worker 重启恢复 | ✅ | ```text API-HEALTH = PASS WORKER-HEALTH = PASS REDIS-HEALTH = PASS RAG-HEALTH = PASS ``` ## 8. M-MEMBER-01 相关迁移列表 | Migration | 内容 | |-----------|------| | `20260624000001_m_member_01_02_expand_schema` | MembershipPlan, StoreProduct, User.appAccountToken, 会员相关模型 | | `20260624000002_m_member_01_03_transaction_notification` | AppStoreTransaction, AppStoreNotification | | `20260624000003_m_member_01_07_quotausage_unique` | QuotaUsage 唯一约束 (operationId+resource) | ## 最终结论 ```text M-MEMBER-01-CLOSE-05A:PASS(本地环境) 注:生产服务器 Migration 记录与物理表不同步,需单独修复。 ```