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>
This commit is contained in:
parent
30b04c6376
commit
4635fea693
|
|
@ -749,7 +749,12 @@
|
|||
"Bash(ssh -o ProxyCommand=\"ssh -W %h:%p ceshi@103.39.231.231\" ceshi@192.168.1.111 \"docker exec rwa-postgres psql -U rwa_user -d rwa_contribution -c ''SELECT * FROM synced_referrals LIMIT 3;''\")",
|
||||
"Bash(ssh -o ProxyCommand=\"ssh -W %h:%p ceshi@103.39.231.231\" ceshi@192.168.1.111 \"docker exec rwa-postgres psql -U rwa_user -d rwa_mining_admin -c ''\\\\d synced_users''\")",
|
||||
"Bash(ssh -o ProxyCommand=\"ssh -W %h:%p ceshi@103.39.231.231\" ceshi@192.168.1.111 \"docker exec rwa-postgres psql -U rwa_user -d rwa_mining_admin -c \"\"SELECT table_name FROM information_schema.tables WHERE table_schema=''public'' ORDER BY table_name;\"\"\")",
|
||||
"Bash(dir /b \"c:\\\\Users\\\\dong\\\\Desktop\\\\rwadurian\\\\backend\\\\services\\\\contribution-service\\\\src\\\\domain\\\\events\")"
|
||||
"Bash(dir /b \"c:\\\\Users\\\\dong\\\\Desktop\\\\rwadurian\\\\backend\\\\services\\\\contribution-service\\\\src\\\\domain\\\\events\")",
|
||||
"Bash(git commit -m \"$\\(cat <<''EOF''\nfeat\\(sync\\): 完善 CDC 数据同步 - 添加推荐关系、认种记录和昵称字段\n\n- auth-service:\n - SyncedLegacyUser 表添加 nickname 字段\n - LegacyUserMigratedEvent 添加 nickname 参数\n - CDC consumer 同步 nickname 字段\n - SyncedLegacyUserData 接口添加 nickname\n\n- contribution-service:\n - 新增 ReferralSyncedEvent 事件类\n - 新增 AdoptionSyncedEvent 事件类\n - admin.controller 添加 publish-all APIs:\n - POST /admin/referrals/publish-all\n - POST /admin/adoptions/publish-all\n\n- mining-admin-service:\n - SyncedUser 表添加 nickname 字段\n - 新增 SyncedReferral 表 \\(推荐关系\\)\n - 新增 SyncedAdoption 表 \\(认种记录\\)\n - handleReferralSynced 处理器\n - handleAdoptionSynced 处理器\n - handleLegacyUserMigrated 处理 nickname\n\n- deploy-mining.sh:\n - full_reset 更新为 14 步\n - Step 13: 发布推荐关系\n - Step 14: 发布认种记录\n\n解决 mining-admin-web 缺少昵称、推荐人、认种数据的问题\n\nCo-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>\nEOF\n\\)\")",
|
||||
"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\")"
|
||||
],
|
||||
"deny": [],
|
||||
"ask": []
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
-- Add nickname field to synced_legacy_users table
|
||||
ALTER TABLE "synced_legacy_users" ADD COLUMN IF NOT EXISTS "nickname" TEXT;
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
-- Add nickname field to synced_users table
|
||||
ALTER TABLE "synced_users" ADD COLUMN IF NOT EXISTS "nickname" TEXT;
|
||||
|
||||
-- Create synced_referrals table for referral relationships
|
||||
CREATE TABLE IF NOT EXISTS "synced_referrals" (
|
||||
"id" TEXT NOT NULL DEFAULT gen_random_uuid()::text,
|
||||
"accountSequence" TEXT NOT NULL,
|
||||
"referrerAccountSequence" TEXT,
|
||||
"referrerUserId" BIGINT,
|
||||
"originalUserId" BIGINT,
|
||||
"ancestorPath" TEXT,
|
||||
"depth" INTEGER NOT NULL DEFAULT 0,
|
||||
"syncedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "synced_referrals_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- Create synced_adoptions table for adoption records
|
||||
CREATE TABLE IF NOT EXISTS "synced_adoptions" (
|
||||
"id" TEXT NOT NULL DEFAULT gen_random_uuid()::text,
|
||||
"originalAdoptionId" BIGINT NOT NULL,
|
||||
"accountSequence" TEXT NOT NULL,
|
||||
"treeCount" INTEGER NOT NULL,
|
||||
"adoptionDate" DATE NOT NULL,
|
||||
"status" TEXT,
|
||||
"contributionPerTree" DECIMAL(20,10) NOT NULL,
|
||||
"syncedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "synced_adoptions_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- Create unique constraints
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "synced_referrals_accountSequence_key" ON "synced_referrals"("accountSequence");
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "synced_adoptions_originalAdoptionId_key" ON "synced_adoptions"("originalAdoptionId");
|
||||
|
||||
-- Create indexes
|
||||
CREATE INDEX IF NOT EXISTS "synced_referrals_referrerAccountSequence_idx" ON "synced_referrals"("referrerAccountSequence");
|
||||
CREATE INDEX IF NOT EXISTS "synced_referrals_depth_idx" ON "synced_referrals"("depth");
|
||||
CREATE INDEX IF NOT EXISTS "synced_adoptions_accountSequence_idx" ON "synced_adoptions"("accountSequence");
|
||||
CREATE INDEX IF NOT EXISTS "synced_adoptions_adoptionDate_idx" ON "synced_adoptions"("adoptionDate");
|
||||
|
||||
-- Add foreign key constraint for synced_referrals
|
||||
ALTER TABLE "synced_referrals" ADD CONSTRAINT "synced_referrals_accountSequence_fkey" FOREIGN KEY ("accountSequence") REFERENCES "synced_users"("accountSequence") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
Loading…
Reference in New Issue