From e337a1dda4e08ab025d9bfb20a7a0c6504a432ab Mon Sep 17 00:00:00 2001 From: hailin Date: Mon, 12 Jan 2026 08:07:16 -0800 Subject: [PATCH] feat(mining-admin): add migration for contribution records and network progress tables - Add synced_contribution_records table for tracking contribution ledger - Add synced_network_progress table for tracking network-wide stats - Revert Dockerfile to use prisma migrate deploy Co-Authored-By: Claude Opus 4.5 --- .../services/mining-admin-service/Dockerfile | 4 +- .../migration.sql | 57 +++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 backend/services/mining-admin-service/prisma/migrations/20260112200000_add_contribution_records_network_progress/migration.sql diff --git a/backend/services/mining-admin-service/Dockerfile b/backend/services/mining-admin-service/Dockerfile index 58eda2ae..81971c08 100644 --- a/backend/services/mining-admin-service/Dockerfile +++ b/backend/services/mining-admin-service/Dockerfile @@ -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 -# 创建启动脚本 - 使用 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 +# 创建启动脚本 +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 ENV NODE_ENV=production ENV TZ=Asia/Shanghai diff --git a/backend/services/mining-admin-service/prisma/migrations/20260112200000_add_contribution_records_network_progress/migration.sql b/backend/services/mining-admin-service/prisma/migrations/20260112200000_add_contribution_records_network_progress/migration.sql new file mode 100644 index 00000000..ff05eee6 --- /dev/null +++ b/backend/services/mining-admin-service/prisma/migrations/20260112200000_add_contribution_records_network_progress/migration.sql @@ -0,0 +1,57 @@ +-- CreateTable +CREATE TABLE "synced_contribution_records" ( + "id" TEXT NOT NULL, + "originalRecordId" BIGINT NOT NULL, + "accountSequence" TEXT NOT NULL, + "sourceType" TEXT NOT NULL, + "sourceAdoptionId" BIGINT NOT NULL, + "sourceAccountSequence" TEXT NOT NULL, + "treeCount" INTEGER NOT NULL, + "baseContribution" DECIMAL(20,10) NOT NULL, + "distributionRate" DECIMAL(10,6) NOT NULL, + "levelDepth" INTEGER, + "bonusTier" INTEGER, + "amount" DECIMAL(30,10) NOT NULL, + "effectiveDate" DATE NOT NULL, + "expireDate" DATE NOT NULL, + "isExpired" BOOLEAN NOT NULL DEFAULT false, + "syncedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "synced_contribution_records_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "synced_network_progress" ( + "id" TEXT NOT NULL, + "totalTreeCount" INTEGER NOT NULL DEFAULT 0, + "totalAdoptionOrders" INTEGER NOT NULL DEFAULT 0, + "totalAdoptedUsers" INTEGER NOT NULL DEFAULT 0, + "currentUnit" INTEGER NOT NULL DEFAULT 0, + "currentMultiplier" DECIMAL(10,6) NOT NULL DEFAULT 1.0, + "currentContributionPerTree" DECIMAL(20,10) NOT NULL DEFAULT 22617, + "nextUnitTreeCount" INTEGER NOT NULL DEFAULT 1000, + "syncedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "synced_network_progress_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "synced_contribution_records_originalRecordId_key" ON "synced_contribution_records"("originalRecordId"); + +-- CreateIndex +CREATE INDEX "synced_contribution_records_accountSequence_idx" ON "synced_contribution_records"("accountSequence"); + +-- CreateIndex +CREATE INDEX "synced_contribution_records_sourceAccountSequence_idx" ON "synced_contribution_records"("sourceAccountSequence"); + +-- CreateIndex +CREATE INDEX "synced_contribution_records_sourceAdoptionId_idx" ON "synced_contribution_records"("sourceAdoptionId"); + +-- CreateIndex +CREATE INDEX "synced_contribution_records_sourceType_idx" ON "synced_contribution_records"("sourceType"); + +-- CreateIndex +CREATE INDEX "synced_contribution_records_createdAt_idx" ON "synced_contribution_records"("createdAt" DESC);