hailin
44f235b185
fix(deploy): add processed_events cleanup for mining-admin-service
...
The full-reset script was missing the cleanup of rwa_mining_admin.processed_events
table, which caused stale idempotency records to prevent re-consumption of
contribution outbox events after reset.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 22:23:44 -08:00
hailin
2a4cb829fe
fix(deploy-mining): truncate processed_cdc_events after CDC offset reset
...
Problem: full-reset script resets Kafka consumer offsets but doesn't
clear the processed_cdc_events table. When migrations run, containers
may start and consume CDC events, inserting records into this table.
After offset reset, the service restarts and detects all events as
"duplicates" because the idempotency records still exist.
Solution: Add TRUNCATE processed_cdc_events step after CDC offset reset
in Step 8, before starting services. This ensures the idempotency table
is in sync with the Kafka offset position.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 21:00:34 -08:00
hailin
61da3652f5
fix(deploy): reorder full-reset steps for proper CDC sync
...
Changes:
1. Delete Debezium connectors BEFORE dropping databases (releases replication slots)
2. Start services BEFORE registering connectors (ensures tables exist and data is synced)
3. Register connectors AFTER services sync from 1.0 CDC (snapshot.mode=initial captures existing data)
4. Add wait time for connectors to initialize before publishing data
Step order: stop services → delete connectors → drop DBs → create DBs → migrate →
start services → wait for sync → register connectors → publish data
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 12:50:07 -08:00
hailin
c31d64550b
fix(deploy): remove duplicate contribution-records/publish-all call
...
The full-reset function was calling contribution-records/publish-all API
which caused duplicate records in mining-admin-service because:
- Contribution records are already published to outbox when calculated
- Debezium automatically captures outbox_events and sends to Kafka
- Calling publish-all again creates duplicate events with different IDs
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 12:29:16 -08:00
hailin
1c33dd7bf3
fix(mining-admin): auto-sync schema on container startup
...
- Change Dockerfile to use `prisma db push` instead of `migrate deploy`
- Add publish steps for contribution records and network progress in full-reset
- This ensures new tables are created automatically when schema changes
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 08:03:38 -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
93c9007045
fix(deploy): 修正 Debezium Connect 默认端口为 8084
...
docker-compose 中 Debezium Connect 映射到 8084 端口
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 02:11:19 -08:00
hailin
40745ca580
feat(cdc): 完善 2.0 服务数据聚合到 mining-admin-service
...
1. deploy-mining.sh:
- 添加 outbox connectors 配置数组 (auth, contribution, mining, trading, wallet)
- 添加 register_outbox_connectors() 函数自动注册 Debezium 连接器
- 添加 outbox-register, outbox-status, outbox-delete 命令
- full-reset 更新为 12 步,包含注册 outbox connectors 和初始数据发布
2. contribution-service:
- 添加 ContributionAccountSyncedEvent 事件
- 添加 POST /admin/contribution-accounts/publish-all API 用于初始全量同步
3. mining-admin-service:
- 添加 ContributionAccountSynced 事件处理(复用 ContributionAccountUpdated 处理器)
- 添加 ContributionCalculated 事件处理
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 01:41:46 -08:00
hailin
489966fae9
feat(auth): 新 1.0 用户自动发布事件到 mining-admin-service
...
- auth-service CDC consumer 在同步新用户时自动发布 LegacyUserMigratedEvent
- 只有 op='c' (create) 的新用户才发布事件,snapshot 由 publish-all API 处理
- deploy-mining.sh full-reset 更新步骤编号为 10 步
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 01:25:01 -08:00
hailin
50854f04d5
fix(deploy): 添加 mining-admin-service-cdc-group 到 CDC 重置列表
...
确保 full-reset 时同时重置 mining-admin-service 的 consumer group,
使其能从头消费所有 outbox 事件。
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 01:18:44 -08:00
hailin
273f2f1d96
fix(deploy): 在 migration 后再次重置 CDC offset
...
问题:migration 会启动容器执行迁移,导致 CDC consumer
自动启动并消费消息。在数据库重建后启动服务时,消息
已经被消费完毕。
解决方案:在 migration 后增加 Step 7,停止容器并
再次重置 CDC offset,确保最终启动时能重新消费。
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 00:53:55 -08:00
hailin
350ce28c40
fix(deploy): 修复 sync-reset CDC offset 重置失败问题
...
- sync_reset() 添加 20 秒等待时间,确保 consumer group 变成 inactive
- 添加重试逻辑(最多 3 次,每次间隔 10 秒)
- 使用 grep NEW-OFFSET 检测 offset reset 是否成功
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 00:49:09 -08:00
hailin
24412794e6
fix(deploy-mining): 修正 full-reset 步骤顺序避免 CDC offset 重置失败
...
- 在 migration 之前重置 CDC offsets(因为 migration 会启动容器)
- 停止服务后等待 15 秒让 Kafka consumer 变成 inactive
- 添加重试机制,最多重试 3 次,每次间隔 10 秒
- 步骤从 6 步改为 7 步
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 00:33:19 -08:00
hailin
ff27195be2
fix(cdc): 修复用户同步字段映射和多 consumer group 重置
...
contribution-service:
- 修复 UserSyncedHandler 使用错误字段名 (data.id -> data.user_id)
- 兼容 CDC snake_case 字段命名 (user_id, account_sequence, phone_number)
- 添加数据验证,跳过无效记录
deploy-mining.sh:
- 添加 auth-service-cdc-group 到 CDC_CONSUMER_GROUPS
- full-reset 现在重置所有 CDC consumer groups
- sync_reset 和 sync_status 支持多个 consumer groups
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 23:59:39 -08:00
hailin
5cab38c7f1
fix(deploy-mining): 修正 Docker 容器名称和默认凭据
...
- 修正 POSTGRES_CONTAINER 为 rwa-postgres (匹配 docker-compose.yml)
- 修正 KAFKA_CONTAINER 为 rwa-kafka
- 修正 POSTGRES_USER 为 rwa_user
- 修正 POSTGRES_PASSWORD 为 rwa_secure_password
- 修复 CDC offset 重置命令使用正确的容器名和命令格式
解决 full-reset 无法删除数据库和重置 CDC offset 的问题。
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 23:41:49 -08:00
hailin
5c302bfca8
fix(deploy-mining): 支持 Docker 环境的数据库操作和迁移
...
- 添加 run_psql helper 函数自动检测 Docker 或本地 psql
- 修改 db_create/db_drop/db_status 使用 docker exec
- 修改 db_migrate 支持通过容器运行 prisma migration
- 修改 health_check/show_stats 支持 Docker 环境
解决在服务器 Docker 环境中 full-reset 失败的问题。
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 23:38:06 -08:00
hailin
83a2800941
refactor(deploy): 移除 mining-admin-web 从 deploy-mining.sh
...
mining-admin-web 是前端项目,不应该在后端服务部署脚本中管理。
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 22:52:26 -08:00
hailin
3c73d510b1
feat(deploy): 添加 mining-wallet-service 到 deploy-mining.sh
...
将 mining-wallet-service 加入 2.0 系统管理脚本:
- 添加到 MINING_SERVICES 数组
- 添加别名 wallet -> mining-wallet-service
- 添加数据库 rwa_mining_wallet
- 添加 SERVICE_DB 映射
- 添加端口 3025
- 更新帮助文档
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 22:51:19 -08:00
hailin
5dab829995
fix(deploy-mining): 修复rebuild命令不更新容器的问题
...
rebuild命令之前只调用build,现在会在构建后停止旧容器并启动新容器
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 18:47:25 -08:00
hailin
ace1e8673b
feat(deploy-mining): rebuild命令增加服务重启功能
...
rebuild命令现在会在构建完成后自动停止旧服务并启动新服务,
而不仅仅是编译镜像。
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 17:18:25 -08:00
hailin
576aad8691
fix(deploy-mining): rebuild默认不使用--no-cache,需显式指定
...
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 23:40:08 -08:00
hailin
0a433eca40
.
2026-01-11 15:14:25 +08:00
hailin
a36bdcdda5
fix(deploy-mining): 使用docker compose替代npm进行构建和部署
...
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 23:11:42 -08:00
hailin
821c70bf38
feat(docker): 添加 2.0 系统 Docker 部署支持
...
为所有 2.0 服务添加 Dockerfile 和 docker-compose 配置:
后端服务:
- contribution-service (3020) - 算力服务
- mining-service (3021) - 挖矿服务
- trading-service (3022) - 交易服务
- mining-admin-service (3023) - 管理后台 API
- auth-service (3024) - 用户认证服务
前端服务:
- mining-admin-web (3100) - 管理后台前端
Docker 配置:
- docker-compose.2.0.yml: 独立的 2.0 系统编排文件
- 多阶段构建优化镜像大小
- 健康检查确保服务可用性
- 服务依赖顺序正确
部署脚本更新:
- deploy-mining.sh 使用 docker-compose.2.0.yml
- 添加 mining-admin-web 服务别名 (web, admin-web)
- 更新服务端口配置
使用方式:
cd backend/services
docker-compose -f docker-compose.2.0.yml up -d
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 19:31:02 -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
hailin
c8c2e63da6
feat(mining): 增强部署脚本支持单服务操作
...
## 新增功能
### 单服务操作
- `up [service]` - 启动全部或指定服务
- `down [service]` - 停止全部或指定服务
- `restart [service]` - 重启全部或指定服务
- `build [service] [--no-cache]` - 构建全部或指定服务
- `rebuild [service]` - 等同于 build --no-cache
### 服务别名
- `contrib`, `contribution` -> contribution-service
- `mining` -> mining-service
- `trading` -> trading-service
- `admin` -> mining-admin-service
### 单服务数据库操作
- `db-create [service]` - 创建全部或指定服务的数据库
- `db-migrate [service]` - 运行全部或指定服务的迁移
- `db-reset [service]` - 重置全部或指定服务的数据库
### 构建功能增强
- `--no-cache` 选项清除 dist/ 和 node_modules/.cache
- 自动运行 npm install
- 自动生成 Prisma client
- 编译 TypeScript
### 状态显示增强
- 显示服务 PID
- 通过端口检测运行状态
- 健康检查端点验证
## 使用示例
```bash
./deploy-mining.sh up mining # 仅启动 mining-service
./deploy-mining.sh restart contrib # 重启 contribution-service
./deploy-mining.sh build trading --no-cache # 清除缓存重新构建
./deploy-mining.sh logs admin 200 # 查看最后200行日志
./deploy-mining.sh db-reset mining # 仅重置 mining-service 数据库
```
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 18:12:38 -08:00
hailin
7c3bf4f068
feat(mining): 添加 2.0 挖矿系统独立部署管理脚本
...
添加 deploy-mining.sh 脚本用于管理 2.0 挖矿生态系统,
该系统与 1.0 完全隔离,可随时重置而不影响 1.0。
## 功能
### 服务管理
- up/down/restart - 启动/停止/重启 2.0 服务
- status - 查看服务状态
- logs [service] - 查看日志
- build - 构建服务
### 数据库管理
- db-create - 创建 2.0 数据库
- db-migrate - 运行 Prisma 迁移
- db-reset - 删除并重建数据库(危险操作)
- db-status - 查看数据库状态
### CDC 同步管理
- sync-reset - 重置 CDC 消费者偏移量到开始位置
- sync-status - 查看 CDC 消费者组状态
### 完整重置
- full-reset - 完整系统重置
1. 停止所有 2.0 服务
2. 删除所有 2.0 数据库
3. 重建数据库
4. 运行迁移
5. 重置 CDC 偏移量
6. 重启服务(从 1.0 重新同步)
### 健康监控
- health - 检查所有组件健康状态
- stats - 显示系统统计信息
## 2.0 服务
- contribution-service (3020)
- mining-service (3021)
- trading-service (3022)
- mining-admin-service (3023)
## 2.0 数据库
- rwa_contribution
- rwa_mining
- rwa_trading
- rwa_mining_admin
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 18:08:16 -08:00