diff --git a/backend/services/admin-service/package.json b/backend/services/admin-service/package.json index 6b7b85c2..69146546 100644 --- a/backend/services/admin-service/package.json +++ b/backend/services/admin-service/package.json @@ -6,7 +6,8 @@ "private": true, "license": "UNLICENSED", "prisma": { - "schema": "prisma/schema.prisma" + "schema": "prisma/schema.prisma", + "seed": "ts-node prisma/seed.ts" }, "scripts": { "build": "nest build", diff --git a/backend/services/admin-service/prisma/seed.ts b/backend/services/admin-service/prisma/seed.ts new file mode 100644 index 00000000..ce27544e --- /dev/null +++ b/backend/services/admin-service/prisma/seed.ts @@ -0,0 +1,79 @@ +import { PrismaClient } from '@prisma/client'; + +const prisma = new PrismaClient(); + +// ============================================ +// 系统账户定义 (与 identity-service/prisma/seed.ts 保持同步) +// ============================================ +const SYSTEM_ACCOUNTS = [ + { + userId: BigInt(1), + accountSequence: 'S0000000001', + nickname: '总部社区', + status: 'SYSTEM', + }, + { + userId: BigInt(2), + accountSequence: 'S0000000002', + nickname: '成本费账户', + status: 'SYSTEM', + }, + { + userId: BigInt(3), + accountSequence: 'S0000000003', + nickname: '运营费账户', + status: 'SYSTEM', + }, + { + userId: BigInt(4), + accountSequence: 'S0000000004', + nickname: 'RWAD底池账户', + status: 'SYSTEM', + }, + { + userId: BigInt(5), + accountSequence: 'D25122100000', + nickname: '种子用户', + status: 'ACTIVE', + }, +]; + +async function main() { + console.log('Seeding admin-service database...'); + + // 同步系统账户到 user_query_view + console.log('Syncing system accounts to user_query_view...'); + for (const account of SYSTEM_ACCOUNTS) { + await prisma.userQueryView.upsert({ + where: { userId: account.userId }, + update: { + accountSequence: account.accountSequence, + nickname: account.nickname, + status: account.status, + syncedAt: new Date(), + }, + create: { + userId: account.userId, + accountSequence: account.accountSequence, + nickname: account.nickname, + status: account.status, + kycStatus: 'NOT_VERIFIED', + registeredAt: new Date(), + syncedAt: new Date(), + }, + }); + console.log(` - Synced: ${account.nickname} (${account.accountSequence})`); + } + + console.log('Admin-service database seeded successfully!'); + console.log(`- Synced ${SYSTEM_ACCOUNTS.length} system accounts to user_query_view`); +} + +main() + .catch((e) => { + console.error(e); + process.exit(1); + }) + .finally(async () => { + await prisma.$disconnect(); + });