Skip to content

Commit 4deb984

Browse files
msjonkerbenjie
andauthored
feat(pg): Adds support for using partitioned table parents (#801)
Co-authored-by: Benjie <[email protected]>
1 parent 7935d7d commit 4deb984

24 files changed

+6269
-4
lines changed

packages/graphile-build-pg/src/plugins/PgIntrospectionPlugin.js

+2
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ export default (async function PgIntrospectionPlugin(
681681
pgIgnoreRBAC = true,
682682
pgSkipInstallingWatchFixtures = false,
683683
pgOwnerConnectionString,
684+
pgUsePartitionedParent = false,
684685
}
685686
) {
686687
/**
@@ -705,6 +706,7 @@ export default (async function PgIntrospectionPlugin(
705706
const introspectionQuery = makeIntrospectionQuery(serverVersionNum, {
706707
pgLegacyFunctionsOnly,
707708
pgIgnoreRBAC,
709+
pgUsePartitionedParent,
708710
});
709711
const { rows } = await pgClient.query(introspectionQuery, [
710712
schemas,

packages/graphile-build-pg/src/plugins/introspectionQuery.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@ function makeIntrospectionQuery(
1212
options: {
1313
pgLegacyFunctionsOnly?: boolean,
1414
pgIgnoreRBAC?: boolean,
15+
pgUsePartitionedParent?: boolean,
1516
} = {}
1617
): string {
17-
const { pgLegacyFunctionsOnly = false, pgIgnoreRBAC = true } = options;
18+
const {
19+
pgLegacyFunctionsOnly = false,
20+
pgIgnoreRBAC = true,
21+
pgUsePartitionedParent = false,
22+
} = options;
1823
const unionRBAC = `
1924
union all
2025
select pg_roles.oid _oid, pg_roles.*
@@ -187,7 +192,11 @@ with
187192
rel.relpersistence in ('p') and
188193
-- We don't want classes that will clash with GraphQL (treat them as private)
189194
rel.relname not like E'\\\\_\\\\_%' and
190-
rel.relkind in ('r', 'v', 'm', 'c', 'f') and
195+
${
196+
pgUsePartitionedParent
197+
? "rel.relkind in ('r', 'v', 'm', 'c', 'f', 'p') and not rel.relispartition"
198+
: "rel.relkind in ('r', 'v', 'm', 'c', 'f')"
199+
} and
191200
($2 is true or not exists(
192201
select 1
193202
from pg_catalog.pg_depend

packages/postgraphile-core/__tests__/helpers-v5.js

+1
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ const makeSchema = config => {
471471
ExtendedPlugin,
472472
config.ToyCategoriesPlugin ? ToyCategoriesPlugin : null,
473473
].filter(isNotNullish),
474+
usePartitionedParent: config.usePartitionedParent,
474475
}
475476
);
476477
});

0 commit comments

Comments
 (0)