You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## 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:
0000)
- [ ] 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
Copy file name to clipboardExpand all lines: packages/prisma-client/prisma/migrations/20251129093846_add_updated_at_to_latest_build_virtual/migration.sql
+49-15Lines changed: 49 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,17 @@
1
1
-- Add updatedAt field to latestBuildVirtual virtual table (type definition)
2
2
-- and update both functions to include Build's updatedAt timestamp
3
+
4
+
-- First, drop existing functions that depend on the old table structure
5
+
DROPFUNCTION IF EXISTS "latestBuildVirtual"("Project");
6
+
DROPFUNCTION IF EXISTS "latestBuildVirtual"("domainsVirtual");
7
+
DROPFUNCTION IF EXISTS "latestProjectDomainBuildVirtual"("Project");
8
+
DROPFUNCTION IF EXISTS "latestBuildVirtual"("DashboardProject");
9
+
3
10
-- Add updatedAt column to the virtual table type definition
4
-
ALTERTABLE
5
-
"latestBuildVirtual"
6
-
ADD
7
-
COLUMN "updatedAt"timestamp(3) with time zoneNOT NULL;
11
+
ALTERTABLE"latestBuildVirtual"
12
+
ADD COLUMN "updatedAt"timestamp(3) with time zoneNOT NULL DEFAULT NOW();
8
13
9
-
COMMENT ON COLUMN "latestBuildVirtual"."updatedAt" IS 'Timestamp indicating when the Build was last updated';
14
+
COMMENT ON COLUMN "public"."latestBuildVirtual"."updatedAt" IS 'Timestamp indicating when the Build was last updated';
10
15
11
16
-- Recreate the function for Project with updatedAt field
12
17
CREATE
@@ -18,7 +23,7 @@ SELECT
18
23
-- Use CASE to determine which domain to select based on conditions
19
24
CASE
20
25
WHEN (b.deployment :: jsonb ->>'projectDomain') =p.domain
21
-
OR (b.deployment :: jsonb ->'domains') @> to_jsonb(array [p.domain]) THEN p.domain
26
+
OR (b.deployment :: jsonb ->'domains') @> to_jsonb(array [p.domain]) THEN p.domain
22
27
ELSE d.domain
23
28
END AS"domain",
24
29
b."createdAt",
@@ -30,7 +35,7 @@ FROM
30
35
LEFT JOIN"ProjectDomain" pd ON pd."projectId"=p.id
31
36
LEFT JOIN"Domain" d ONd.id= pd."domainId"
32
37
WHERE
33
-
b."projectId"= $1.id
38
+
b."projectId"= $1.id
34
39
ANDb.deploymentIS NOT NULL-- 'destination' IS NULL for backward compatibility; 'destination' = 'saas' for non-static builds
35
40
AND (
36
41
(b.deployment :: jsonb ->>'destination') IS NULL
@@ -39,8 +44,8 @@ WHERE
39
44
AND (
40
45
-- Check if 'projectDomain' matches p.domain
41
46
(b.deployment :: jsonb ->>'projectDomain') =p.domain-- Check if 'domains' contains p.domain or d.domain
42
-
OR (b.deployment :: jsonb ->'domains') @> to_jsonb(array [p.domain])
43
-
OR (b.deployment :: jsonb ->'domains') @> to_jsonb(array [d.domain])
47
+
OR (b.deployment :: jsonb ->'domains') @> to_jsonb(array [p.domain])
48
+
OR (b.deployment :: jsonb ->'domains') @> to_jsonb(array [d.domain])
44
49
)
45
50
ORDER BY
46
51
b."createdAt"DESC
@@ -65,11 +70,11 @@ SELECT
65
70
b."updatedAt"
66
71
FROM
67
72
"Build" b
68
-
JOIN"Domain" d ONd.id= $1."domainId"
73
+
JOIN"Domain" d ONd.id= $1."domainId"
69
74
WHERE
70
-
b."projectId"= $1."projectId"
75
+
b."projectId"= $1."projectId"
71
76
ANDb.deploymentIS NOT NULL
72
-
AND (b.deployment :: jsonb ->'domains') @> to_jsonb(array [d.domain])
77
+
AND (b.deployment :: jsonb ->'domains') @> to_jsonb(array [d.domain])
73
78
ORDER BY
74
79
b."createdAt"DESC
75
80
LIMIT
@@ -96,15 +101,15 @@ FROM
96
101
JOIN"Project" p ON b."projectId"=p.id
97
102
LEFT JOIN"ProjectDomain" pd ON pd."projectId"=p.id
98
103
WHERE
99
-
b."projectId"= $1.id
104
+
b."projectId"= $1.id
100
105
ANDb.deploymentIS NOT NULL
101
106
AND (
102
107
(b.deployment :: jsonb ->>'destination') IS NULL
103
108
OR (b.deployment :: jsonb ->>'destination') ='saas'
OR (b.deployment :: jsonb ->'domains') @> to_jsonb(array [p.domain])
112
+
OR (b.deployment :: jsonb ->'domains') @> to_jsonb(array [p.domain])
108
113
)
109
114
ORDER BY
110
115
b."createdAt"DESC
@@ -113,4 +118,33 @@ LIMIT
113
118
114
119
$$ STABLE LANGUAGE sql;
115
120
116
-
COMMENT ON FUNCTION "latestProjectDomainBuildVirtual"("Project") IS 'This function computes the latest build for a project domain, ensuring it is a production (non-static) build, where the domain matches either the Project.domain field or exists in the related Domain table. It provides backward compatibility for older records with a missing "destination" field.';
121
+
COMMENT ON FUNCTION "latestProjectDomainBuildVirtual"("Project") IS 'This function computes the latest build for a project domain, ensuring it is a production (non-static) build, where the domain matches either the Project.domain field or exists in the related Domain table. It provides backward compatibility for older records with a missing "destination" field.';
122
+
123
+
-- Add latestBuildVirtual function overload for DashboardProject view
124
+
-- This is needed because PostgREST computed fields require a function
125
+
-- that matches the source table/view type. DashboardProject is a view
126
+
-- over Project, so we need this wrapper function that casts to Project type.
127
+
CREATE
128
+
OR REPLACE FUNCTION "latestBuildVirtual"("DashboardProject") RETURNS SETOF "latestBuildVirtual" ROWS 1AS $$
COMMENT ON FUNCTION "latestBuildVirtual"("DashboardProject") IS 'Wrapper function to make latestBuildVirtual work with DashboardProject view for PostgREST computed fields.';
137
+
138
+
-- Grant execute permissions to all PostgREST roles
139
+
-- Uses DO block to check if roles exist before granting (prevents errors if roles are missing)
140
+
DO $$
141
+
DECLARE
142
+
role_name TEXT;
143
+
BEGIN
144
+
FOREACH role_name IN ARRAY ARRAY['anon', 'authenticated', 'service_role']
145
+
LOOP
146
+
IF EXISTS (SELECT1FROM pg_roles WHERE rolname = role_name) THEN
147
+
EXECUTE format('GRANT EXECUTE ON FUNCTION "latestBuildVirtual"("DashboardProject") TO %I', role_name);
Copy file name to clipboardExpand all lines: packages/prisma-client/prisma/migrations/20251130131728_add_latest_build_virtual_for_dashboard_project/migration.sql
0 commit comments