refactor: 统一模板契约并修复预览版本
This commit is contained in:
1 parent
cd2992c00a
commit
50b87e48de
56 files changed
+7849
-5756
No files matched your search
+107
@@ -0,0 +1,107 @@
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM "BrandTemplateInstallation"
|
||||
GROUP BY "brandId"
|
||||
HAVING COUNT(*) > 1
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Template contract migration stopped: a brand has multiple template installations';
|
||||
END IF;
|
||||
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM "BrandTemplateInstallation" installation
|
||||
LEFT JOIN "TemplatePackageVersion" package_version
|
||||
ON package_version."id" = installation."templatePackageVersionId"
|
||||
WHERE installation."templatePackageVersionId" IS NULL
|
||||
OR package_version."id" IS NULL
|
||||
OR package_version."status" <> 'published'
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Template contract migration stopped: an installation has no exact package version';
|
||||
END IF;
|
||||
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM "BrandTemplateInstallation" installation
|
||||
JOIN "TemplatePackageVersion" package_version
|
||||
ON package_version."id" = installation."templatePackageVersionId"
|
||||
JOIN "BrandProfile" brand ON brand."id" = installation."brandId"
|
||||
WHERE installation."visualTemplateKey" IS DISTINCT FROM package_version."visualTemplateKey"
|
||||
OR package_version."visualTemplateKey" IS DISTINCT FROM package_version."packageKey"
|
||||
OR package_version."manifestSnapshot"->>'visualTemplateKey' IS DISTINCT FROM package_version."visualTemplateKey"
|
||||
OR package_version."manifestSnapshot"->>'packageKey' IS DISTINCT FROM package_version."packageKey"
|
||||
OR package_version."manifestSnapshot"->>'version' IS DISTINCT FROM package_version."version"
|
||||
OR NOT COALESCE(package_version."manifestSnapshot"->'supportedIndustryTemplates' ? brand."templateKey", false)
|
||||
OR installation."templateKey" IS DISTINCT FROM brand."templateKey"
|
||||
OR (installation."contentChecksum" IS NOT NULL AND installation."contentChecksum" IS DISTINCT FROM package_version."contentChecksum")
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Template contract migration stopped: installation, brand, package row, or manifest disagree';
|
||||
END IF;
|
||||
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM "BrandProfile" brand
|
||||
LEFT JOIN "BrandTemplateInstallation" installation ON installation."brandId" = brand."id"
|
||||
WHERE installation."id" IS NULL
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Template contract migration stopped: a brand has no explicit template installation';
|
||||
END IF;
|
||||
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM "BrandProfile" brand
|
||||
JOIN "BrandTemplateInstallation" installation ON installation."brandId" = brand."id"
|
||||
JOIN "TemplatePackageVersion" package_version
|
||||
ON package_version."id" = installation."templatePackageVersionId"
|
||||
WHERE brand."config" ? 'visualTemplateKey'
|
||||
AND brand."config"->>'visualTemplateKey' IS DISTINCT FROM package_version."visualTemplateKey"
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Template contract migration stopped: brand config visualTemplateKey conflicts with its installation';
|
||||
END IF;
|
||||
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM "BrandProfile" brand
|
||||
LEFT JOIN "BrandTemplateInstallation" installation ON installation."brandId" = brand."id"
|
||||
WHERE brand."config" ? 'visualTemplateKey'
|
||||
AND installation."id" IS NULL
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Template contract migration stopped: brand config visualTemplateKey has no installation to verify against';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM "TemplatePackageVersion" package_version
|
||||
WHERE package_version."visualTemplateKey" IS DISTINCT FROM package_version."packageKey"
|
||||
OR package_version."manifestSnapshot"->>'visualTemplateKey' IS DISTINCT FROM package_version."packageKey"
|
||||
OR package_version."manifestSnapshot"->>'packageKey' IS DISTINCT FROM package_version."packageKey"
|
||||
OR package_version."manifestSnapshot"->>'version' IS DISTINCT FROM package_version."version"
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Template contract migration stopped: package metadata conflicts with its manifest';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
UPDATE "BrandTemplateInstallation" installation
|
||||
SET "templateVersion" = package_version."version",
|
||||
"contentChecksum" = package_version."contentChecksum"
|
||||
FROM "TemplatePackageVersion" package_version
|
||||
WHERE package_version."id" = installation."templatePackageVersionId";
|
||||
|
||||
UPDATE "BrandProfile"
|
||||
SET "config" = "config" - 'visualTemplateKey'
|
||||
WHERE "config" ? 'visualTemplateKey';
|
||||
|
||||
ALTER TABLE "BrandTemplateInstallation"
|
||||
DROP CONSTRAINT "BrandTemplateInstallation_templatePackageVersionId_fkey",
|
||||
DROP COLUMN "visualTemplateKey",
|
||||
ALTER COLUMN "templatePackageVersionId" SET NOT NULL,
|
||||
ADD CONSTRAINT "BrandTemplateInstallation_templatePackageVersionId_fkey"
|
||||
FOREIGN KEY ("templatePackageVersionId") REFERENCES "TemplatePackageVersion"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "TemplatePackageVersion" DROP COLUMN "visualTemplateKey";
|
||||
|
||||
DROP INDEX "BrandTemplateInstallation_brandId_templateKey_key";
|
||||
CREATE UNIQUE INDEX "BrandTemplateInstallation_brandId_key" ON "BrandTemplateInstallation"("brandId");
|
||||
Reference in new issue
Block a user