-
Notifications
You must be signed in to change notification settings - Fork 967
/
data-migration.ts
57 lines (48 loc) · 1.36 KB
/
data-migration.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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;
}
const updates = products.map(product => {
if (product.styling !== null) {
// styling object already exists for this product
return;
}
const styling: TStyling = {
unifiedStyling: true,
allowStyleOverwrite: true,
brandColor: {
light: product.brandColor,
},
...(product.highlightBorderColor && {
highlightBorderColor: {
light: product.highlightBorderColor,
dark: product.highlightBorderColor,
},
}),
};
return tx.product.update({
where: {
id: product.id,
},
data: {
styling,
},
});
});
await tx.$transaction(updates);
});
}
main()
.catch(async (e) => {
console.error(e);
process.exit(1);
})
.finally(async () => await prisma.$disconnect());