fix(mining-wallet-service): use upsert in seed for 100% overwrite
Remove existence check, directly upsert pool accounts to ensure consistent state on every seed run. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
fdff3a3119
commit
4440f40fba
|
|
@ -66,6 +66,7 @@ async function main() {
|
||||||
// 积分股池A: 100亿 (10,000,000,000) - 用于销毁
|
// 积分股池A: 100亿 (10,000,000,000) - 用于销毁
|
||||||
// 积分股池B: 200万 (2,000,000) - 用于挖矿分配
|
// 积分股池B: 200万 (2,000,000) - 用于挖矿分配
|
||||||
// 总计: 100.02亿 (10,002,000,000)
|
// 总计: 100.02亿 (10,002,000,000)
|
||||||
|
// 直接 upsert 覆盖,不检查是否存在
|
||||||
const poolAccounts = [
|
const poolAccounts = [
|
||||||
{
|
{
|
||||||
poolType: 'SHARE_POOL_A',
|
poolType: 'SHARE_POOL_A',
|
||||||
|
|
@ -95,49 +96,28 @@ async function main() {
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const pool of poolAccounts) {
|
for (const pool of poolAccounts) {
|
||||||
const existing = await prisma.poolAccount.findFirst({
|
const created = await prisma.poolAccount.upsert({
|
||||||
where: { poolType: pool.poolType as any },
|
where: { poolType: pool.poolType as any },
|
||||||
|
update: {
|
||||||
|
name: pool.name,
|
||||||
|
balance: pool.balance,
|
||||||
|
targetBurn: pool.targetBurn,
|
||||||
|
remainingBurn: pool.targetBurn,
|
||||||
|
description: pool.description,
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
poolType: pool.poolType as any,
|
||||||
|
name: pool.name,
|
||||||
|
balance: pool.balance,
|
||||||
|
targetBurn: pool.targetBurn,
|
||||||
|
remainingBurn: pool.targetBurn,
|
||||||
|
description: pool.description,
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!existing) {
|
console.log(`Upserted pool account: ${pool.poolType}`);
|
||||||
const created = await prisma.poolAccount.create({
|
|
||||||
data: {
|
|
||||||
poolType: pool.poolType as any,
|
|
||||||
name: pool.name,
|
|
||||||
balance: pool.balance,
|
|
||||||
targetBurn: pool.targetBurn,
|
|
||||||
remainingBurn: pool.targetBurn,
|
|
||||||
description: pool.description,
|
|
||||||
isActive: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// 发布池账户创建事件到 Outbox
|
|
||||||
await prisma.outboxEvent.create({
|
|
||||||
data: {
|
|
||||||
aggregateType: 'PoolAccount',
|
|
||||||
aggregateId: created.id,
|
|
||||||
eventType: 'WalletPoolAccountCreated',
|
|
||||||
topic: 'mining-wallet.pool-account.created',
|
|
||||||
key: created.poolType,
|
|
||||||
payload: {
|
|
||||||
id: created.id,
|
|
||||||
poolType: created.poolType,
|
|
||||||
name: created.name,
|
|
||||||
balance: created.balance.toString(),
|
|
||||||
totalInflow: 0,
|
|
||||||
totalOutflow: 0,
|
|
||||||
targetBurn: created.targetBurn?.toString() || null,
|
|
||||||
remainingBurn: created.remainingBurn?.toString() || null,
|
|
||||||
isActive: created.isActive,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log(`Created pool account: ${pool.poolType}`);
|
|
||||||
} else {
|
|
||||||
console.log(`Pool account already exists: ${pool.poolType}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Seeding completed!');
|
console.log('Seeding completed!');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue