Oleg Isonen cd0174807d chore: use console.info instead of console.log (#3049)
## Description

We allow console.info (btw we should also allow warn/error/info), we
only disallow console.log in the linter because that's what we use for
debugging.

## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @TrySound , I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env.example`
and the `builder/env-check.js` if mandatory
2024-03-24 12:52:46 +01:00

86 lines
2.3 KiB
TypeScript

import { PrismaClient } from "./client";
import { z } from "zod";
const PageSchema = z.object({
id: z.string(),
name: z.string(),
path: z.string(),
title: z.string(),
meta: z.record(z.string(), z.string()),
treeId: z.string(),
});
const PagesSchema = z.object({
homePage: PageSchema,
pages: z.array(PageSchema),
});
export default () => {
const client = new PrismaClient({
// Uncomment to see the queries in console as the migration runs
// log: ["query", "info", "warn", "error"],
});
return client.$transaction(
async (prisma) => {
const builds = await prisma.build.findMany();
const breakpoints = await prisma.breakpoints.findMany();
const buildsParsed = builds.map((build) => ({
id: build.id,
pages: PagesSchema.parse(JSON.parse(build.pages)),
}));
// await Promise.all(
// breakpoints.map((breakpoint) => {
// const build = buildsParsed.find(
// (build) => build.pages.homePage.treeId === breakpoint.treeId
// );
// if (build === undefined) {
//
// console.warn(
// `Build not found for breakpoint ${breakpoint.treeId}. Deleting!`
// );
// return prisma.breakpoints.delete({
// where: { treeId: breakpoint.treeId },
// });
// }
// return prisma.breakpoints.update({
// where: { treeId: breakpoint.treeId },
// data: {
// buildId: build.id,
// },
// });
// })
// );
for (const breakpoint of breakpoints) {
const build = buildsParsed.find(
(build) => build.pages.homePage.treeId === breakpoint.treeId
);
if (build === undefined) {
console.warn(
`Build not found for breakpoint ${breakpoint.treeId}. Deleting!`
);
await prisma.breakpoints.delete({
where: { treeId: breakpoint.treeId },
});
} else {
console.info(`Updating breakpoint ${breakpoint.treeId}`);
await prisma.breakpoints.update({
where: { treeId: breakpoint.treeId },
data: {
buildId: build.id,
},
});
}
}
},
{ timeout: 1000 * 60 * 15 }
);
};