feat: 建立漂流瓶权威数据模型

This commit is contained in:
root
2026-09-14 11:10:57 +08:00
parent 18450201dc
commit a2a5e4bd0f
11 changed files with 1926 additions and 11 deletions
+63
View File
@@ -0,0 +1,63 @@
import { createHash } from "node:crypto";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
const id = (value: string) => createHash("sha256").update(value).digest("hex");
async function seed(): Promise<void> {
const accounts = await Promise.all(
[
{ key: "demo-a", nickname: "海风" },
{ key: "demo-b", nickname: "星河" },
].map(({ key, nickname }) =>
prisma.account.upsert({
where: { phoneHmac: id(`drift-bottle:${key}:phone-hmac`) },
update: {
anonymousProfile: {
upsert: { create: { nickname }, update: { nickname } },
},
},
create: {
phoneCiphertext: Buffer.from(
id(`drift-bottle:${key}:ciphertext`),
"hex",
),
phoneHmac: id(`drift-bottle:${key}:phone-hmac`),
anonymousProfile: { create: { nickname } },
},
}),
),
);
const author = accounts[0];
if (!author) throw new Error("Seed author was not created");
await prisma.bottle.upsert({
where: { id: "00000000-0000-4000-8000-000000000101" },
update: {
authorId: author.id,
contentText: "愿你今天遇见温柔。",
status: "IN_POOL",
},
create: {
id: "00000000-0000-4000-8000-000000000101",
authorId: author.id,
contentText: "愿你今天遇见温柔。",
status: "IN_POOL",
},
});
console.info(
"Seed complete: 2 demo accounts, 2 anonymous profiles, 1 in-pool bottle.",
);
}
seed()
.catch((error: unknown) => {
console.error(
"Seed failed",
error instanceof Error ? error.message : "unknown error",
);
process.exitCode = 1;
})
.finally(async () => prisma.$disconnect());