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>
This commit is contained in:
hailin 2026-01-12 08:03:38 -08:00
parent bf5a16939f
commit 1c33dd7bf3
3 changed files with 34 additions and 4 deletions

View File

@ -754,7 +754,8 @@
"Bash(ssh -o StrictHostKeyChecking=no ceshi@103.39.231.231 \"ssh -o StrictHostKeyChecking=no ceshi@192.168.1.111 ''cd /home/ceshi/rwadurian/backend/services && git pull''\")",
"Bash(ssh -o StrictHostKeyChecking=no ceshi@103.39.231.231 \"ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ceshi@192.168.1.111 ''cd /home/ceshi/rwadurian/backend/services && git pull''\")",
"Bash(set DATABASE_URL=postgresql://user:pass@localhost:5432/db)",
"Bash(cmd /c \"set DATABASE_URL=postgresql://user:pass@localhost:5432/db && npx prisma migrate dev --name add_nickname_to_synced_legacy_users --create-only\")"
"Bash(cmd /c \"set DATABASE_URL=postgresql://user:pass@localhost:5432/db && npx prisma migrate dev --name add_nickname_to_synced_legacy_users --create-only\")",
"Bash(dir \"c:\\\\Users\\\\dong\\\\Desktop\\\\rwadurian\\\\frontend\")"
],
"deny": [],
"ask": []

View File

@ -1042,7 +1042,7 @@ full_reset() {
log_info "You may need to manually call: curl -X POST $referral_publish_url"
fi
log_step "Step 14/14: Publishing adoption records to mining-admin-service..."
log_step "Step 14/17: Publishing adoption records to mining-admin-service..."
# 调用 contribution-service API 发布所有认种记录事件到 outbox
local adoption_publish_url="http://localhost:3020/api/v2/admin/adoptions/publish-all"
local adoption_result
@ -1057,6 +1057,35 @@ full_reset() {
log_info "You may need to manually call: curl -X POST $adoption_publish_url"
fi
log_step "Step 15/17: Publishing contribution records to mining-admin-service..."
# 调用 contribution-service API 发布所有算力记录事件到 outbox
local records_publish_url="http://localhost:3020/api/v2/admin/contribution-records/publish-all"
local records_result
records_result=$(curl -s -X POST "$records_publish_url" 2>/dev/null || echo '{"error": "curl failed"}')
if echo "$records_result" | grep -q '"success":true'; then
local records_count
records_count=$(echo "$records_result" | grep -o '"publishedCount":[0-9]*' | grep -o '[0-9]*')
log_success "Published $records_count contribution record events to outbox"
else
log_warn "Failed to publish contribution records: $records_result"
log_info "You may need to manually call: curl -X POST $records_publish_url"
fi
log_step "Step 16/17: Publishing network progress to mining-admin-service..."
# 调用 contribution-service API 发布全网进度事件到 outbox
local progress_publish_url="http://localhost:3020/api/v2/admin/network-progress/publish"
local progress_result
progress_result=$(curl -s -X POST "$progress_publish_url" 2>/dev/null || echo '{"error": "curl failed"}')
if echo "$progress_result" | grep -q '"success":true'; then
log_success "Published network progress to outbox"
else
log_warn "Failed to publish network progress: $progress_result"
log_info "You may need to manually call: curl -X POST $progress_publish_url"
fi
log_step "Step 17/17: Waiting for mining-admin-service to sync all data..."
# 等待 mining-admin-service 消费 outbox 事件
log_info "Waiting 15 seconds for mining-admin-service to sync all data..."
sleep 15

View File

@ -53,8 +53,8 @@ RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate
# 复制构建产物
COPY --chown=nestjs:nodejs --from=builder /app/dist ./dist
# 创建启动脚本
RUN printf '#!/bin/sh\nset -e\necho "Running database migrations..."\nnpx prisma migrate deploy\necho "Starting application..."\nexec node dist/main.js\n' > /app/start.sh && chmod +x /app/start.sh
# 创建启动脚本 - 使用 db push 而不是 migrate deploy此服务不使用迁移文件
RUN printf '#!/bin/sh\nset -e\necho "Syncing database schema..."\nnpx prisma db push --accept-data-loss\necho "Starting application..."\nexec node dist/main.js\n' > /app/start.sh && chmod +x /app/start.sh
ENV NODE_ENV=production
ENV TZ=Asia/Shanghai