fix: schema

This commit is contained in:
pandeymangg
2024-02-29 11:51:45 +05:30
parent b84e322eee
commit 71bdb5095a
5 changed files with 3 additions and 63 deletions

View File

@@ -1,54 +0,0 @@
import { PrismaClient } from "@prisma/client";
import { TStyling } from "@formbricks/types/styling";
const prisma = new PrismaClient();
async function main() {
await prisma.$transaction(async (tx) => {
// product table with brand color and the highlight border color (if available)
// styling object needs to be created for each product
const products = await tx.product.findMany({});
if (!products) {
// something went wrong, could not find any products
return;
}
if (products.length) {
for (const product of products) {
if (product.styling !== null) {
// styling object already exists for this product
continue;
}
const styling: TStyling = {
brandColor: {
light: product.brandColor,
},
...(product.highlightBorderColor && {
highlightBorderColor: {
light: product.highlightBorderColor,
},
}),
};
await tx.product.update({
where: {
id: product.id,
},
data: {
styling,
},
});
}
}
});
}
main()
.catch(async (e) => {
console.error(e);
process.exit(1);
})
.finally(async () => await prisma.$disconnect());

View File

@@ -1,4 +0,0 @@
-- AlterTable
ALTER TABLE "Product" ADD COLUMN "allowStyleOverwrite" BOOLEAN DEFAULT true,
ADD COLUMN "styling" JSONB,
ADD COLUMN "unifiedStyling" BOOLEAN DEFAULT true;

View File

@@ -420,9 +420,7 @@ model Product {
highlightBorderColor String?
/// @zod.custom(imports.ZStyling)
/// [Styling]
styling Json?
unifiedStyling Boolean? @default(true)
allowStyleOverwrite Boolean? @default(true)
styling Json? @default("{\"unifiedStyling\":true,\"allowStyleOverwrite\":true,\"brandColor\":{\"light\":\"#64748b\"}}")
recontactDays Int @default(7)
linkSurveyBranding Boolean @default(true) // Determines if the survey branding should be displayed in link surveys
inAppSurveyBranding Boolean @default(true) // Determines if the survey branding should be displayed in in-app surveys

View File

@@ -13,8 +13,6 @@ export const ZProduct = z.object({
brandColor: ZColor,
highlightBorderColor: ZColor.nullable(),
styling: ZStyling.nullable(),
unifiedStyling: z.boolean().nullable(),
allowStyleOverwrite: z.boolean().nullable(),
recontactDays: z.number().int(),
inAppSurveyBranding: z.boolean(),
linkSurveyBranding: z.boolean(),

View File

@@ -15,6 +15,8 @@ export const ZCardArrangement = z.object({
});
export const ZStyling = z.object({
unifiedStyling: z.boolean(),
allowStyleOverwrite: z.boolean(),
brandColor: ZStylingColor.optional(),
questionColor: ZStylingColor.optional(),
inputColor: ZStylingColor.optional(),