Skip to content

Commit a24b51b

Browse files
committed
::migrate:: fix updatedAt column check with explicit schema
1 parent 9ab7671 commit a24b51b

File tree

3 files changed

+43
-54
lines changed
  • .github/workflows
  • packages/prisma-client/prisma/migrations
    • 20251129093846_add_updated_at_to_latest_build_virtual
    • 20251130131728_add_latest_build_virtual_for_dashboard_project

3 files changed

+43
-54
lines changed

.github/workflows/migrate.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ jobs:
5757
env:
5858
DIRECT_URL: ${{ secrets.DIRECT_URL }}
5959

60-
# Execute db tests (@todo: can be done only after applying the migrations, now always())
60+
# Execute db tests (runs after migrations, even if they fail)
6161
db-tests:
62+
# Always run tests to see failures on CI, but only after migrate job completes
6263
if: always()
6364

6465
needs: [migrate]
@@ -75,7 +76,7 @@ jobs:
7576

7677
- uses: pnpm/action-setup@v4
7778

78-
- name: pnpm instal
79+
- name: Run database tests
7980
run: pnpm -r db-test
8081
env:
8182
DIRECT_URL: ${{ secrets.DIRECT_URL }}

packages/prisma-client/prisma/migrations/20251129093846_add_updated_at_to_latest_build_virtual/migration.sql

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
-- Add updatedAt field to latestBuildVirtual virtual table (type definition)
22
-- and update both functions to include Build's updatedAt timestamp
33
-- Add updatedAt column to the virtual table type definition (only if it doesn't exist)
4-
DO $$ BEGIN IF NOT EXISTS (
5-
SELECT
6-
1
7-
FROM
8-
information_schema.columns
9-
WHERE
10-
table_name = 'latestBuildVirtual'
11-
AND column_name = 'updatedAt'
12-
) THEN
13-
ALTER TABLE
14-
"latestBuildVirtual"
15-
ADD
16-
COLUMN "updatedAt" timestamp(3) with time zone NOT NULL;
17-
18-
END IF;
19-
4+
DO $$
5+
BEGIN
6+
IF NOT EXISTS (
7+
SELECT 1
8+
FROM information_schema.columns
9+
WHERE table_schema = 'public'
10+
AND table_name = 'latestBuildVirtual'
11+
AND column_name = 'updatedAt'
12+
) THEN
13+
ALTER TABLE "latestBuildVirtual"
14+
ADD COLUMN "updatedAt" timestamp(3) with time zone NOT NULL;
15+
END IF;
2016
END $$;
2117

2218
COMMENT ON COLUMN "latestBuildVirtual"."updatedAt" IS 'Timestamp indicating when the Build was last updated';

packages/prisma-client/prisma/migrations/20251130131728_add_latest_build_virtual_for_dashboard_project/migration.sql

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,32 @@ $$ STABLE LANGUAGE sql;
2323
COMMENT ON FUNCTION "latestBuildVirtual"("DashboardProject") IS 'Wrapper function to make latestBuildVirtual work with DashboardProject view for PostgREST computed fields.';
2424

2525
-- Grant execute permissions to all PostgREST roles (only if they exist)
26-
DO $$ BEGIN -- Grant to anon if role exists
27-
IF EXISTS (
28-
SELECT
29-
1
30-
FROM
31-
pg_roles
32-
WHERE
33-
rolname = 'anon'
34-
) THEN GRANT EXECUTE ON FUNCTION "latestBuildVirtual"("DashboardProject") TO anon;
35-
36-
END IF;
37-
38-
-- Grant to authenticated if role exists
39-
IF EXISTS (
40-
SELECT
41-
1
42-
FROM
43-
pg_roles
44-
WHERE
45-
rolname = 'authenticated'
46-
) THEN GRANT EXECUTE ON FUNCTION "latestBuildVirtual"("DashboardProject") TO authenticated;
47-
48-
END IF;
49-
50-
-- Grant to service_role if role exists
51-
IF EXISTS (
52-
SELECT
53-
1
54-
FROM
55-
pg_roles
56-
WHERE
57-
rolname = 'service_role'
58-
) THEN GRANT EXECUTE ON FUNCTION "latestBuildVirtual"("DashboardProject") TO service_role;
59-
60-
END IF;
61-
26+
DO $$
27+
BEGIN
28+
-- Grant to anon if role exists
29+
IF EXISTS (
30+
SELECT 1
31+
FROM pg_roles
32+
WHERE rolname = 'anon'
33+
) THEN
34+
GRANT EXECUTE ON FUNCTION "latestBuildVirtual"("DashboardProject") TO anon;
35+
END IF;
36+
37+
-- Grant to authenticated if role exists
38+
IF EXISTS (
39+
SELECT 1
40+
FROM pg_roles
41+
WHERE rolname = 'authenticated'
42+
) THEN
43+
GRANT EXECUTE ON FUNCTION "latestBuildVirtual"("DashboardProject") TO authenticated;
44+
END IF;
45+
46+
-- Grant to service_role if role exists
47+
IF EXISTS (
48+
SELECT 1
49+
FROM pg_roles
50+
WHERE rolname = 'service_role'
51+
) THEN
52+
GRANT EXECUTE ON FUNCTION "latestBuildVirtual"("DashboardProject") TO service_role;
53+
END IF;
6254
END $$;

0 commit comments

Comments
 (0)