hailin
e00c81153b
docs(migrations): add detailed comments for idempotency tables
...
- Add comments explaining unique key composition:
- CDC events: (source_topic, offset) = Kafka topic + message offset
- Outbox events: (source_service, event_id) = service name + outbox ID
- Fix contribution-service migration:
- Extend source_service column from VARCHAR(50) to VARCHAR(100)
- Set source_service as NOT NULL to match schema
- Use snake_case for index name consistency
- Clarify that offset/event_id are NOT database auto-increment IDs
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 19:44:46 -08:00
hailin
9037c2da97
feat(auth): implement transactional idempotent CDC consumer for 1.0->2.0 sync
...
Implements 100% exactly-once semantics for CDC events from 1.0 identity-service
(user_accounts table) to auth-service.
Key changes:
- Add ProcessedCdcEvent model with (sourceTopic, offset) unique constraint
- Implement processWithIdempotency() using Serializable transaction isolation
- All database operations now use the transaction client
- Outbox event creation is also within the same transaction
This ensures that:
1. Each CDC event is processed exactly once
2. Idempotency record and business logic are in the same transaction
3. Outbox event publishing is atomic with data sync
4. Any failure causes complete rollback
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 19:29:42 -08:00
hailin
bfafd6d34c
refactor(prisma): consolidate migrations into single init files
...
Merge multiple incremental migrations into single init migration for each service:
- auth-service: 3 migrations → 1 (user auth, SMS, KYC)
- contribution-service: 4 migrations → 1 (contribution accounts, 15-level hierarchy, 3-tier bonus)
- mining-admin-service: 6 migrations → 1 (admin, CDC sync tables, prisma relation mode)
- mining-service: 1 migration (no change needed, renamed for consistency)
- mining-wallet-service: 3 migrations → 1 (wallet system, removed blockchain tables)
- trading-service: 1 migration (no change needed, renamed for consistency)
All migrations renamed from timestamp format (20260111000000_*) to sequential format (0001_init)
for cleaner migration history.
Note: Requires clearing _prisma_migrations table before applying to existing databases.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 11:04:24 -08:00
hailin
7b310c554b
fix(migrations): 修复数据库迁移脚本语法
...
- 移除 IF NOT EXISTS,使用标准 Prisma 迁移格式
- 确保 full-reset 能正确执行迁移
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:07:14 -08:00
hailin
4635fea693
chore(migrations): 添加数据库迁移脚本
...
- auth-service: 20260112110000_add_nickname_to_synced_legacy_users
- synced_legacy_users 表添加 nickname 字段
- mining-admin-service: 20260112110000_add_referral_adoption_nickname
- synced_users 表添加 nickname 字段
- 创建 synced_referrals 表 (推荐关系)
- 创建 synced_adoptions 表 (认种记录)
- 相关索引和外键约束
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 03:02:55 -08:00
hailin
30b04c6376
feat(sync): 完善 CDC 数据同步 - 添加推荐关系、认种记录和昵称字段
...
- auth-service:
- SyncedLegacyUser 表添加 nickname 字段
- LegacyUserMigratedEvent 添加 nickname 参数
- CDC consumer 同步 nickname 字段
- SyncedLegacyUserData 接口添加 nickname
- contribution-service:
- 新增 ReferralSyncedEvent 事件类
- 新增 AdoptionSyncedEvent 事件类
- admin.controller 添加 publish-all APIs:
- POST /admin/referrals/publish-all
- POST /admin/adoptions/publish-all
- mining-admin-service:
- SyncedUser 表添加 nickname 字段
- 新增 SyncedReferral 表 (推荐关系)
- 新增 SyncedAdoption 表 (认种记录)
- handleReferralSynced 处理器
- handleAdoptionSynced 处理器
- handleLegacyUserMigrated 处理 nickname
- deploy-mining.sh:
- full_reset 更新为 14 步
- Step 13: 发布推荐关系
- Step 14: 发布认种记录
解决 mining-admin-web 缺少昵称、推荐人、认种数据的问题
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 02:48:15 -08:00
hailin
849fa77df0
fix(auth-service): 允许synced_legacy_users的phone和password_hash为空
...
- 修改schema让phone和passwordHash字段可为空
- 添加migration: 20260111083500_allow_nullable_phone_password
- CDC consumer使用null替代空字符串
- 支持同步没有手机号/密码的系统账户
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 08:37:02 -08:00
hailin
51456373a9
feat(2.0-services): 添加所有服务的初始Prisma migrations
...
使用 prisma migrate diff 生成初始数据库迁移脚本:
- mining-admin-service: 管理后台相关表及CDC同步表
- auth-service: 用户认证相关表
- trading-service: 交易相关表
- mining-wallet-service: 钱包相关表
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 00:06:46 -08:00
hailin
f7278b6196
feat(auth-service): 添加用户认证服务2.0
...
实现完整的用户认证服务,支持1.0用户迁移和2.0新用户注册:
功能特性:
- 用户注册(生成V2格式accountSequence: 15位)
- 密码登录(支持V1迁移用户和V2用户)
- V1用户首次登录自动迁移到2.0系统
- 短信验证码发送/验证(注册/登录/重置密码/更换手机号)
- 密码管理(重置密码、修改密码)
- KYC实名认证(提交/审核资料)
- JWT认证(Access Token + Refresh Token)
技术架构:
- DDD六边形架构(Domain/Application/Infrastructure/API)
- Prisma ORM + PostgreSQL
- CDC消费者同步1.0用户数据
- Outbox模式发布领域事件
- NestJS ThrottlerModule限流
数据模型:
- User: 2.0用户表(含KYC字段)
- SyncedLegacyUser: CDC同步的1.0用户(只读)
- RefreshToken: 刷新令牌
- SmsVerification: 短信验证码
- DailySequenceCounter: 每日序号计数器
- OutboxEvent: 发件箱事件
AccountSequence格式:
- V1: D + YYMMDD + 5位序号 = 12字符
- V2: D + YYMMDD + 8位序号 = 15字符
服务端口:3024
数据库:rwa_auth
同时更新deploy-mining.sh添加auth-service支持。
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 18:50:59 -08:00