Skip to content

Commit 57da5fd

Browse files
committed
only create postgrest role if it doesn't exist 🐛; 4.8.2
1 parent 22a564a commit 57da5fd

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

index.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ ${opt.schema !== 'public' ? `\
250250
DO
251251
$$
252252
BEGIN
253+
-- Roles are shared across databases, so we have remove previously configured privileges.
254+
-- This might of course interfere with other programs running on the DBMS!
255+
-- todo: find a cleaner solution
253256
IF EXISTS (
254257
SELECT FROM pg_catalog.pg_roles
255258
WHERE rolname = 'web_anon'
256259
) THEN
257-
-- Roles are shared across databases, so we have remove previously configured privileges.
258-
-- This might of course interfere with other programs running on the DBMS!
259-
-- todo: find a cleaner solution
260260
RAISE WARNING 'Role web_anon already exists. Reassigning owned DB objects to current_user().';
261261
REASSIGN OWNED BY web_anon TO SESSION_USER;
262262
-- REVOKE ALL PRIVILEGES ON DATABASE current_database() FROM web_anon;
@@ -271,6 +271,24 @@ BEGIN
271271
RAISE NOTICE 'Role web_anon was just created by a concurrent transaction.';
272272
END;
273273
END IF;
274+
IF EXISTS (
275+
SELECT FROM pg_catalog.pg_roles
276+
WHERE rolname = 'postgrest'
277+
) THEN
278+
RAISE WARNING 'Role postgrest already exists. Reassigning owned DB objects to current_user().';
279+
REASSIGN OWNED BY postgrest TO SESSION_USER;
280+
-- REVOKE ALL PRIVILEGES ON DATABASE current_database() FROM postgrest;
281+
-- REVOKE ALL PRIVILEGES ON SCHEMA "${opt.schema}" FROM postgrest;
282+
-- REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA "${opt.schema}" FROM postgrest;
283+
-- REVOKE ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA "${opt.schema}" FROM postgrest;
284+
ELSE
285+
BEGIN
286+
CREATE ROLE postgrest LOGIN NOINHERIT NOCREATEDB NOCREATEROLE NOSUPERUSER PASSWORD '${postgrestPassword}';
287+
EXCEPTION
288+
WHEN duplicate_object THEN
289+
RAISE NOTICE 'Role postgrest was just created by a concurrent transaction.';
290+
END;
291+
END IF;
274292
END
275293
$$;
276294
@@ -283,7 +301,6 @@ GRANT SELECT ON ALL TABLES IN SCHEMA "${opt.schema}" TO web_anon;
283301
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA "${opt.schema}" TO web_anon;
284302
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA "${opt.schema}" TO web_anon;
285303
286-
CREATE ROLE postgrest LOGIN NOINHERIT NOCREATEDB NOCREATEROLE NOSUPERUSER PASSWORD '${postgrestPassword}';
287304
GRANT web_anon TO postgrest;
288305
289306
COMMENT ON SCHEMA "${opt.schema}" IS

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gtfs-via-postgres",
33
"description": "Process GTFS using PostgreSQL.",
4-
"version": "4.8.1",
4+
"version": "4.8.2",
55
"main": "lib/index.js",
66
"bin": {
77
"gtfs-to-sql": "cli.js",

0 commit comments

Comments
 (0)