Skip to content

Commit 7b74bc0

Browse files
author
Oskar Hurst
committed
reorder repeatables
1 parent 31a3b78 commit 7b74bc0

3 files changed

Lines changed: 18 additions & 74 deletions

File tree

sql/common/R__07_grants_user_regions.sql

Lines changed: 0 additions & 46 deletions
This file was deleted.

sql/common/R__08_functions_user_regions.sql

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,6 @@
44
-- User Regions
55
-------------------------
66

7-
-- DEBUG: Show Flyway migration history in logs
8-
DO $$
9-
DECLARE
10-
migration_history TEXT;
11-
BEGIN
12-
SELECT string_agg(
13-
format('installed_rank: %s | version: %s | description: %s | type: %s | script: %s | checksum: %s | installed_on: %s | execution_time: %s | success: %s',
14-
installed_rank,
15-
COALESCE(version, 'NULL'),
16-
description,
17-
type,
18-
script,
19-
COALESCE(checksum::TEXT, 'NULL'),
20-
installed_on,
21-
execution_time,
22-
success
23-
),
24-
E'\n'
25-
ORDER BY installed_rank DESC
26-
)
27-
INTO migration_history
28-
FROM flyway_schema_history
29-
ORDER BY installed_rank DESC
30-
LIMIT 20;
31-
32-
RAISE EXCEPTION E'FLYWAY MIGRATION HISTORY (last 20):\n%', migration_history;
33-
END $$;
34-
357
-- Function to validate GeoJSON before saving
368
CREATE OR REPLACE FUNCTION validate_user_region_geojson()
379
RETURNS TRIGGER AS $$
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- Repeatable migration to ensure user_region permissions are always correct
2+
-- This runs every time migrations are applied to ensure permissions are set
3+
4+
-- Grant permissions to cumulus_user (the API user)
5+
GRANT USAGE ON SCHEMA cumulus TO cumulus_user;
6+
GRANT SELECT, INSERT, UPDATE, DELETE ON cumulus.user_region TO cumulus_user;
7+
GRANT SELECT ON cumulus.v_user_region TO cumulus_user;
8+
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA cumulus TO cumulus_user;
9+
10+
-- Also ensure cumulus_user can access other required tables for the view
11+
GRANT SELECT ON cumulus.download TO cumulus_user;
12+
13+
-- Log what we did
14+
DO $$
15+
BEGIN
16+
RAISE NOTICE 'Granted user_region permissions to cumulus_user';
17+
END
18+
$$;

0 commit comments

Comments
 (0)