From 46fc5d8f8cce1a5f9d82a87853821d8cd4315ca2 Mon Sep 17 00:00:00 2001 From: Ivan Starkov Date: Sat, 10 Aug 2024 01:21:18 +0300 Subject: [PATCH] chore: Add timezone (#3913) ## Description 1. What is this PR about (link the issue and add a short description) ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, 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` file --- .../20240809220753_tz/migration.sql | 110 ++++++++++++++++++ packages/prisma-client/prisma/schema.prisma | 5 +- 2 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 packages/prisma-client/prisma/migrations/20240809220753_tz/migration.sql diff --git a/packages/prisma-client/prisma/migrations/20240809220753_tz/migration.sql b/packages/prisma-client/prisma/migrations/20240809220753_tz/migration.sql new file mode 100644 index 000000000000..ff42d62e6c22 --- /dev/null +++ b/packages/prisma-client/prisma/migrations/20240809220753_tz/migration.sql @@ -0,0 +1,110 @@ +DROP VIEW "LatestStaticBuildPerProject"; +DROP VIEW "LatestBuildPerProject"; + +DROP VIEW "LatestBuildPerProjectDomain"; + +-- AlterTable +ALTER TABLE "Build" ALTER COLUMN "updatedAt" SET DATA TYPE TIMESTAMPTZ(3); + +CREATE OR REPLACE VIEW "LatestStaticBuildPerProject" AS +SELECT DISTINCT ON ("projectId") + bld.id AS "buildId", + bld."projectId", + bld."updatedAt", + bld."publishStatus" +FROM + "Build" bld +WHERE + bld.deployment IS NOT NULL + AND bld.deployment::jsonb ->> 'destination'::text = 'static' +ORDER BY + bld."projectId", + bld."createdAt" DESC, + "buildId"; + +CREATE OR REPLACE VIEW "LatestBuildPerProject" AS +WITH lb AS ( + SELECT DISTINCT ON ("projectId") + bld.id AS "buildId", + bld."projectId", + bld."updatedAt" + FROM + "Build" bld + WHERE + bld.deployment IS NOT NULL + AND bld.deployment::jsonb ->> 'projectDomain'::text IS NOT NULL + ORDER BY + bld."projectId", + bld."createdAt" DESC, + "buildId" +) +SELECT DISTINCT ON ("projectId", "domain") + bld.id AS "buildId", + bld."projectId", + deployment::jsonb ->> 'projectDomain' AS domain, + coalesce(bld."updatedAt" = lb."updatedAt", FALSE) AS "isLatestBuild", + bld."updatedAt", + bld."publishStatus" +FROM + "Build" bld, + lb +WHERE + bld.deployment IS NOT NULL + AND lb."projectId" = bld."projectId" + AND bld.deployment::jsonb ->> 'projectDomain'::text IS NOT NULL +ORDER BY + bld."projectId", + "domain", + bld."createdAt" DESC, + "buildId"; + + +CREATE OR REPLACE VIEW "LatestBuildPerProjectDomain" AS +WITH lbd AS ( + SELECT DISTINCT ON ("projectId", + "domain") + jsonb_array_elements_text(deployment::jsonb -> 'domains') AS "domain", + bld.id AS "buildId", + bld."projectId", + bld."updatedAt", + bld."publishStatus" + FROM + "Build" bld + WHERE + bld.deployment IS NOT NULL + ORDER BY + bld."projectId", + "domain", + bld."createdAt" DESC, + "buildId" +), +lb AS ( + SELECT DISTINCT ON ("projectId") + bld.id AS "buildId", + bld."projectId", + bld."updatedAt", + bld."publishStatus" + FROM + "Build" bld + WHERE + bld.deployment IS NOT NULL + AND bld.deployment::jsonb ->> 'projectDomain'::text IS NOT NULL + ORDER BY + bld."projectId", + bld."createdAt" DESC, + "buildId" +) +SELECT + d.id AS "domainId", + lbd."projectId", + lbd."buildId", + coalesce(lbd."updatedAt" = lb."updatedAt", FALSE) AS "isLatestBuild", + lbd."publishStatus", + lbd."updatedAt" +FROM + lbd, + lb, + "Domain" d +WHERE + lbd.domain = d.domain + AND lb."projectId" = lbd."projectId"; \ No newline at end of file diff --git a/packages/prisma-client/prisma/schema.prisma b/packages/prisma-client/prisma/schema.prisma index df8caec175ff..a1f429bd252a 100644 --- a/packages/prisma-client/prisma/schema.prisma +++ b/packages/prisma-client/prisma/schema.prisma @@ -181,8 +181,9 @@ model Build { version Int @default(0) lastTransactionId String? createdAt DateTime @default(now()) - updatedAt DateTime @default(now()) @updatedAt - pages String + updatedAt DateTime @default(now()) @updatedAt @db.Timestamptz(3) + + pages String project Project @relation(fields: [projectId], references: [id]) projectId String