Skip to content

Commit 8e828f7

Browse files
committed
DuckDB rewrite: remove PostgreSQL-specific features πŸ’₯βœ…πŸ’šπŸ“
1 parent 42d3151 commit 8e828f7

27 files changed

+3
-3117
lines changed

β€Ž.github/workflows/test.ymlβ€Ž

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,6 @@ jobs:
5454
PGPASSWORD: password
5555
PGDATABASE: postgres
5656

57-
- name: install PostgREST
58-
run: |
59-
set -euo pipefail
60-
set -x
61-
dl_url="$(
62-
curl -fsSL \
63-
-H "User-Agent: $user_agent" \
64-
-H 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
65-
'https://api.github.com/repos/PostgREST/postgrest/releases/latest' \
66-
| jq -rc '.assets[] | select(.name | test("linux-static-x86-64")) | .browser_download_url'
67-
)"
68-
wget -nv -U "$user_agent" \
69-
--header='Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
70-
-O /tmp/postgrest.tar.xz \
71-
"$dl_url"
72-
tar -C /usr/local/bin -J -x postgrest </tmp/postgrest.tar.xz
73-
/usr/local/bin/postgrest --version
74-
env:
75-
user_agent: 'public-transport/gtfs-via-postgres CI'
76-
7757
- run: npm install
7858

7959
- run: npm run lint

β€Žcli.jsβ€Ž

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,6 @@ const {
5959
'schema': {
6060
type: 'string',
6161
},
62-
'postgraphile': {
63-
type: 'boolean',
64-
},
65-
'postgraphile-password': {
66-
type: 'string',
67-
},
68-
'postgrest': {
69-
type: 'boolean',
70-
},
71-
'postgrest-password': {
72-
type: 'string',
73-
},
74-
'postgrest-query-cost-limit': {
75-
type: 'string',
76-
},
7762
'import-metadata': {
7863
type: 'boolean',
7964
}
@@ -130,21 +115,6 @@ Options:
130115
gets created, to ensure that multiple imports into the
131116
same database are all made using the same version. See
132117
also multiple-datasets.md in the docs.
133-
--postgraphile Tweak generated SQL for PostGraphile usage.
134-
https://www.graphile.org/postgraphile/
135-
--postgraphile-password Password for the PostGraphile PostgreSQL user.
136-
Default: $POSTGRAPHILE_PGPASSWORD, fallback random.
137-
--postgrest Tweak generated SQL for PostgREST usage.
138-
Please combine it with --schema.
139-
https://postgrest.org/
140-
--postgrest-password Password for the PostgREST PostgreSQL user \`web_anon\`.
141-
Default: $POSTGREST_PGPASSWORD, fallback random.
142-
--postgrest-query-cost-limit Define a cost limit [1] for queries executed by PostgREST
143-
on behalf of a user. It is only enforced if
144-
pg_plan_filter [2] is installed in the database!
145-
Must be a positive float. Default: none
146-
[1] https://www.postgresql.org/docs/14/using-explain.html
147-
[2] https://github.com/pgexperts/pg_plan_filter
148118
--import-metadata Create functions returning import metadata:
149119
- gtfs_data_imported_at (timestamp with time zone)
150120
- gtfs_via_postgres_version (text)
@@ -186,8 +156,6 @@ const opt = {
186156
statsByAgencyIdAndRouteIdAndStopAndHour: flags['stats-by-agency-route-stop-hour'] || 'none',
187157
statsActiveTripsByHour: flags['stats-active-trips-by-hour'] || 'none',
188158
schema: flags['schema'] || 'public',
189-
postgraphile: !!flags.postgraphile,
190-
postgrest: !!flags.postgrest,
191159
importMetadata: !!flags['import-metadata'],
192160
}
193161
if ('stops-without-level-id' in flags) {
@@ -196,20 +164,6 @@ if ('stops-without-level-id' in flags) {
196164
if ('lower-case-lang-codes' in flags) {
197165
opt.lowerCaseLanguageCodes = flags['lower-case-lang-codes']
198166
}
199-
if ('postgraphile-password' in flags) {
200-
opt.postgraphilePassword = flags['postgraphile-password']
201-
}
202-
if ('postgrest-password' in flags) {
203-
opt.postgrestPassword = flags['postgrest-password']
204-
}
205-
if ('postgrest-query-cost-limit' in flags) {
206-
const limit = parseFloat(flags['postgrest-query-cost-limit'])
207-
if (!Number.isFinite(limit) || limit < 0) {
208-
console.error('Invalid --postgrest-query-cost-limit value.')
209-
process.exit(1)
210-
}
211-
opt.lowerCaseLanguageCodes = limit
212-
}
213167

214168
pipeline(
215169
convertGtfsToSql(files, opt),

β€Ždocs/import-metadata.mdβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SELECT gtfs_via_postgres_version()
1212
-- 4.5.3
1313

1414
SELECT gtfs_via_postgres_options()
15-
-- {"schema": "public", "silent": false, "importStart": 1681417454781, "postgraphile": false, "importMetadata": true, … }
15+
-- {"schema": "public", "silent": false, "importStart": 1681417454781, "importMetadata": true, … }
1616
SELECT (gtfs_via_postgres_options())['tripsWithoutShapeId']
1717
-- true
1818
```

β€Ždocs/postgrest.mdβ€Ž

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

β€Žindex.jsβ€Ž

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ const convertGtfsToSql = async function* (files, opt = {}) {
2626
statsByAgencyIdAndRouteIdAndStopAndHour: 'none',
2727
statsActiveTripsByHour: 'none',
2828
schema: 'public',
29-
postgraphile: false,
30-
postgraphilePassword: process.env.POSTGRAPHILE_PGPASSWORD || null,
31-
postgrest: false,
32-
postgrestPassword: process.env.POSTGREST_PASSWORD || null,
33-
// see https://github.com/pgexperts/pg_plan_filter
34-
// see also https://www.postgresql.org/docs/14/using-explain.html
35-
postgrestQueryCostLimit: null, // or float
3629
importMetadata: false,
3730
...opt,
3831
}
@@ -47,16 +40,6 @@ const convertGtfsToSql = async function* (files, opt = {}) {
4740
statsByAgencyIdAndRouteIdAndStopAndHour,
4841
statsActiveTripsByHour,
4942
} = opt
50-
let postgraphilePassword = opt.postgraphilePassword
51-
if (opt.postgraphile && postgraphilePassword === null) {
52-
postgraphilePassword = randomBytes(10).toString('hex')
53-
console.error(`PostGraphile PostgreSQL user's password:`, postgraphilePassword)
54-
}
55-
let postgrestPassword = opt.postgrestPassword
56-
if (opt.postgrest && postgrestPassword === null) {
57-
postgrestPassword = randomBytes(10).toString('hex')
58-
console.error(`PostrREST PostgreSQL user's password:`, postgrestPassword)
59-
}
6043

6144
if (ignoreUnsupportedFiles) {
6245
files = files.filter(f => !!formatters[f.name])
@@ -255,104 +238,6 @@ LANGUAGE sql;
255238
}
256239

257240
yield `\
258-
259-
${opt.postgraphile ? `\
260-
-- seal imported data
261-
-- todo:
262-
-- > Be careful with public schema.It already has a lot of default privileges that you maybe don't want... See documentation[1].
263-
-- > [1]: postgresql.org/docs/11/ddl-schemas.html#DDL-SCHEMAS-PRIV
264-
DO $$
265-
BEGIN
266-
-- https://stackoverflow.com/questions/8092086/create-postgresql-role-user-if-it-doesnt-exist#8099557
267-
IF EXISTS (
268-
SELECT FROM pg_catalog.pg_roles
269-
WHERE rolname = 'postgraphile'
270-
) THEN
271-
RAISE NOTICE 'Role "postgraphile" already exists, skipping creation.';
272-
ELSE
273-
CREATE ROLE postgraphile LOGIN PASSWORD '${opt.postgraphilePassword}'; -- todo: escape properly
274-
END IF;
275-
END
276-
$$;
277-
DO $$
278-
DECLARE
279-
db TEXT := current_database();
280-
BEGIN
281-
-- todo: grant just on $opt.schema instead?
282-
EXECUTE format('GRANT ALL PRIVILEGES ON DATABASE %I TO %I', db, 'postgraphile');
283-
END
284-
$$;
285-
GRANT USAGE ON SCHEMA "${opt.schema}" TO postgraphile;
286-
-- https://stackoverflow.com/questions/760210/how-do-you-create-a-read-only-user-in-postgresql#comment50679407_762649
287-
REVOKE CREATE ON SCHEMA "${opt.schema}" FROM PUBLIC;
288-
GRANT SELECT ON ALL TABLES IN SCHEMA "${opt.schema}" TO postgraphile;
289-
-- ALTER DEFAULT PRIVILEGES IN SCHEMA "${opt.schema}" GRANT SELECT ON TABLES TO postgraphile;
290-
-- todo: set search_path? https://stackoverflow.com/questions/760210/how-do-you-create-a-read-only-user-in-postgresql#comment33535263_762649
291-
` : ''}
292-
293-
${opt.postgrest ? `\
294-
${opt.schema !== 'public' ? `\
295-
-- pattern from https://stackoverflow.com/a/8099557
296-
DO
297-
$$
298-
BEGIN
299-
-- Roles are shared across databases, so we have remove previously configured privileges.
300-
-- This might of course interfere with other programs running on the DBMS!
301-
-- todo: find a cleaner solution
302-
IF EXISTS (
303-
SELECT FROM pg_catalog.pg_roles
304-
WHERE rolname = 'web_anon'
305-
) THEN
306-
RAISE WARNING 'Role web_anon already exists. Reassigning owned DB objects to current_user().';
307-
REASSIGN OWNED BY web_anon TO SESSION_USER;
308-
ELSE
309-
BEGIN
310-
CREATE ROLE web_anon NOLOGIN NOINHERIT;
311-
EXCEPTION
312-
WHEN duplicate_object THEN
313-
RAISE NOTICE 'Role web_anon was just created by a concurrent transaction.';
314-
END;
315-
END IF;
316-
IF EXISTS (
317-
SELECT FROM pg_catalog.pg_roles
318-
WHERE rolname = 'postgrest'
319-
) THEN
320-
RAISE WARNING 'Role postgrest already exists. Reassigning owned DB objects to current_user().';
321-
REASSIGN OWNED BY postgrest TO SESSION_USER;
322-
ELSE
323-
BEGIN
324-
CREATE ROLE postgrest LOGIN NOINHERIT NOCREATEDB NOCREATEROLE NOSUPERUSER PASSWORD '${postgrestPassword}';
325-
EXCEPTION
326-
WHEN duplicate_object THEN
327-
RAISE NOTICE 'Role postgrest was just created by a concurrent transaction.';
328-
END;
329-
END IF;
330-
END
331-
$$;
332-
333-
334-
-- https://postgrest.org/en/stable/tutorials/tut0.html#step-4-create-database-for-api
335-
-- https://postgrest.org/en/stable/explanations/db_authz.html
336-
-- todo: is this secure?
337-
GRANT USAGE ON SCHEMA "${opt.schema}" TO web_anon;
338-
GRANT SELECT ON ALL TABLES IN SCHEMA "${opt.schema}" TO web_anon;
339-
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA "${opt.schema}" TO web_anon;
340-
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA "${opt.schema}" TO web_anon;
341-
342-
GRANT web_anon TO postgrest;
343-
344-
${opt.postgrestQueryCostLimit !== null ? `
345-
-- If pg_plan_filter is installed, limit the cost of queries made by PostgREST users.
346-
ALTER USER web_anon SET plan_filter.statement_cost_limit = ${opt.postgrestQueryCostLimit};
347-
` : ''}
348-
349-
COMMENT ON SCHEMA "${opt.schema}" IS
350-
$$GTFS REST API
351-
This REST API is created by running [PostgREST](https://postgrest.org/) on top of a [PostgreSQL](https://www.postgresql.org) DB generated using [${pkg.name} v${pkg.version}](${pkg.homepage || pkg.repository}).
352-
$$;
353-
` : ''}
354-
` : ''}
355-
356241
COMMIT;`
357242
}
358243

β€Žlib/calendar_dates.jsβ€Ž

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ const afterAll = (opt) => `\
4141
4242
CREATE INDEX ON "${opt.schema}".calendar_dates (service_id);
4343
CREATE INDEX ON "${opt.schema}".calendar_dates (exception_type);
44-
45-
${opt.postgraphile ? `\
46-
COMMENT ON TABLE "${opt.schema}".calendar_dates IS E'@foreignKey (service_id) references calendar|@fieldName calendar';
47-
` : ''}
4844
`
4945

5046
module.exports = {

β€Žlib/pathways.jsβ€Ž

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ const formatPathwaysRow = (p) => {
8484

8585
const afterAll = (opt) => `\
8686
\\.
87-
88-
${opt.postgraphile ? `\
89-
CREATE INDEX ON "${opt.schema}".pathways (from_stop_id);
90-
CREATE INDEX ON "${opt.schema}".pathways (to_stop_id);
91-
` : ''}
9287
`
9388

9489
module.exports = {

β€Žlib/prerequisites.jsβ€Ž

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ AS $$
2222
);
2323
$$ language sql STABLE;
2424
25-
${opt.postgraphile ? `\
26-
COMMENT ON FUNCTION "${opt.schema}".is_bcp_47_tag IS E'@omit';
27-
` : ''}
28-
2925
-- todo [breaking]: remove
3026
CREATE OR REPLACE FUNCTION "${opt.schema}".is_valid_lang_code(
3127
input TEXT
@@ -36,9 +32,6 @@ AS $$
3632
SELECT "${opt.schema}".is_bcp_47_tag(input);
3733
$$ language sql STABLE;
3834
39-
${opt.postgraphile ? `\
40-
COMMENT ON FUNCTION "${opt.schema}".is_valid_lang_code IS E'@omit';
41-
` : ''}
4235
`,
4336
}
4437
const is_timezone = {
@@ -59,9 +52,6 @@ AS $$
5952
END;
6053
$$ language plpgsql STABLE;
6154
62-
${opt.postgraphile ? `\
63-
COMMENT ON FUNCTION "${opt.schema}".is_timezone IS E'@omit';
64-
` : ''}
6555
`,
6656
}
6757
const shape_exists = {
@@ -79,9 +69,6 @@ AS $$
7969
);
8070
$$ language sql STABLE;
8171
82-
${opt.postgraphile ? `\
83-
COMMENT ON FUNCTION "${opt.schema}".shape_exists IS E'@omit';
84-
` : ''}
8572
`,
8673
}
8774

β€Žlib/routes.jsβ€Ž

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,6 @@ CREATE TYPE "${opt.schema}".route_type_val AS ENUM (
257257
${extRouteTypes.map(([route_type, desc]) => `, '${route_type}' -- ${desc}`).join('\n')}
258258
);
259259
CREATE CAST ("${opt.schema}".route_type_val AS text) WITH INOUT AS IMPLICIT;
260-
-- todo [breaking]: use small table as enum? https://www.graphile.org/postgraphile/enums/#with-enum-tables
261-
${opt.postgraphile ? `\
262-
COMMENT ON TYPE "${opt.schema}".route_type_val IS E'@enum\\n@enumName RouteType\\n';
263-
` : ''}
264260
265261
CREATE TABLE "${opt.schema}".routes (
266262
route_id TEXT PRIMARY KEY,
@@ -328,9 +324,6 @@ const afterAll = (opt) => `\
328324
\\.
329325
330326
CREATE INDEX ON "${opt.schema}".routes (route_short_name);
331-
${opt.postgraphile ? `\
332-
CREATE INDEX ON "${opt.schema}".routes (agency_id);
333-
` : ''}
334327
`
335328

336329
module.exports = {

β€Žlib/service_days.jsβ€Ž

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ CREATE INDEX ON "${opt.schema}".service_days (date);
6868
-- apparently the unique index (service_id, date) doesn't speed up queries
6969
CREATE INDEX ON "${opt.schema}".service_days (service_id, date);
7070
71-
${opt.postgraphile ? `\
72-
COMMENT ON MATERIALIZED VIEW "${opt.schema}".service_days IS E'@name serviceDates\\n@primaryKey service_id,date';
73-
` : ''}
7471
`
7572

7673
module.exports = {

0 commit comments

Comments
Β (0)