graphile / crystal

🔮 Graphile's Crystal Monorepo; home to Grafast, PostGraphile, pg-introspection, pg-sql2 and much more!
https://graphile.org/
Other
12.62k stars 571 forks source link

graphile-export: Exporting a schema against a Postgres v17 database throws an error during introspection #2200

Closed mattiarossi closed 1 month ago

mattiarossi commented 1 month ago

During our migration tests from postgres 16 to 17, exporting a schema using graphile-export throws an error during introspection:

node dist/util/exporter.mjs 
//tools/postgraphile-schema-dump/node_modules/pg-introspection/dist/acl.js:63
        throw new Error(`Could not parse ACL string '${aclString}'`);
              ^

Error: Could not parse ACL string 'api=arwdDxtm/api'
    at parseAcl (//tools/postgraphile-schema-dump/node_modules/pg-introspection/dist/acl.js:63:15)
    at //tools/postgraphile-schema-dump/node_modules/pg-introspection/dist/acl.js:314:48
    at Array.map (<anonymous>)
    at parseAcls (//tools/postgraphile-schema-dump/node_modules/pg-introspection/dist/acl.js:314:29)
    at //tools/postgraphile-schema-dump/node_modules/pg-introspection/dist/augmentIntrospection.js:154:59
    at Object.getACL (//tools/postgraphile-schema-dump/node_modules/pg-introspection/dist/augmentIntrospection.js:14:21)
    at entityPermissions (//tools/postgraphile-schema-dump/node_modules/pg-introspection/dist/acl.js:462:25)
    at pgCodecs_attribute (//tools/postgraphile-schema-dump/node_modules/graphile-build-pg/dist/plugins/PgRBACPlugin.js:39:83)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async //tools/postgraphile-schema-dump/node_modules/graphile-build-pg/dist/plugins/PgCodecsPlugin.js:183:29

Node.js v22.9.0

The line that throws the error is: https://github.com/graphile/crystal/blob/3f64cc8e7ed50f0d3654c15ec8660b09ca6e7f91/utils/pg-introspection/src/acl.ts#L142

The introspection failing because PG17 added a new MAINTAINER default privilege (shortcode: m) and the regular expression does not match that. The export process can be temporarily fixed by adding the new shortcode to the match, but I see the code then proceeeds to create logical representations of the premission to be made available elsewhere, so a real fix will probably involve underatsnding what the new privilege is meant for and how does that affect postgraphile logic ... flagging it as requested in Discord