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