refactor: 统一模板契约并修复预览版本

This commit is contained in:
que01 committed 2026-10-18 17:09:09 +08:00
1 parent cd2992c00a
commit 50b87e48de
56 files changed
+7849 -5756

No files matched your search

+26 -8
View File
@@ -1,4 +1,5 @@
import assert from "node:assert/strict";
import { getTemplatePackageManifestForVisualKey } from "@personal-brand/config";
import { PrismaService } from "../dist/prisma.service.js";
import { TemplateWorkspaceService } from "../dist/template-workspace.service.js";
@@ -19,18 +20,12 @@ try {
let current = await tx.brandProfile.findUnique({ where: { slug } });
if (current) {
assert.equal(current.templateKey, "personal", "Existing brand has a different industry");
assert.equal(
current.config?.visualTemplateKey,
"atelier-solopreneur",
"Existing brand has a different visual template",
);
} else {
current = await tx.brandProfile.create({
data: {
slug,
name: "独立工坊 · 品牌小程序",
templateKey: "personal",
config: { visualTemplateKey: "atelier-solopreneur" },
},
});
}
@@ -41,8 +36,31 @@ try {
});
return current;
});
if (!(await prisma.brandTemplateInstallation.findFirst({ where: { brandId: brand.id } }))) {
await new TemplateWorkspaceService(prisma).install(brand.id, "personal");
const manifest = getTemplatePackageManifestForVisualKey("atelier-solopreneur");
if (!manifest) throw new Error("atelier-solopreneur package manifest is unavailable");
const version = await prisma.templatePackageVersion.findUnique({
where: {
templatePackageId_version: {
templatePackageId: (
await prisma.templatePackage.findUniqueOrThrow({
where: { packageKey: "atelier-solopreneur" },
select: { id: true },
})
).id,
version: manifest.version,
},
},
});
if (!version || version.status !== "published")
throw new Error(`Published package version not found: atelier-solopreneur@${manifest.version}`);
const installation = await prisma.brandTemplateInstallation.findUnique({
where: { brandId: brand.id },
include: { templatePackageVersion: true },
});
if (installation) {
assert.equal(installation.templatePackageVersionId, version.id);
} else {
await new TemplateWorkspaceService(prisma).install(brand.id, "personal", version.id);
}
assert.deepEqual(
await prisma.brandProfile.findMany({ where: { slug: { not: slug } }, orderBy: { id: "asc" } }),
@@ -10,8 +10,14 @@ const prisma = new PrismaClient();
const note = "餐饮主理人原型视觉槽位迁移 v1";
try {
const brand = await prisma.brandProfile.findUniqueOrThrow({ where: { slug: "default-brand" } });
const config = (brand.config ?? {}) as Record<string, unknown>;
if (brand.templateKey !== "food" || config.visualTemplateKey !== "acheng-campus-food")
const installation = await prisma.brandTemplateInstallation.findUnique({
where: { brandId: brand.id },
include: { templatePackageVersion: true },
});
if (
brand.templateKey !== "food" ||
installation?.templatePackageVersion?.packageKey !== "acheng-campus-food"
)
throw new Error("Migration is restricted to the development food brand");
const previous = await prisma.brandRelease.findFirst({
where: { brandId: brand.id },