Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pg): Adds support for using partitioned table parents #801

Merged
merged 7 commits into from Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -657,6 +657,7 @@ export default (async function PgIntrospectionPlugin(
pgIgnoreRBAC = true,
pgSkipInstallingWatchFixtures = false,
pgOwnerConnectionString,
pgUsePartitionedParent = false,
}
) {
/**
Expand All @@ -681,6 +682,7 @@ export default (async function PgIntrospectionPlugin(
const introspectionQuery = makeIntrospectionQuery(serverVersionNum, {
pgLegacyFunctionsOnly,
pgIgnoreRBAC,
pgUsePartitionedParent,
});
const { rows } = await pgClient.query(introspectionQuery, [
schemas,
Expand Down
13 changes: 11 additions & 2 deletions packages/graphile-build-pg/src/plugins/introspectionQuery.js
Expand Up @@ -12,9 +12,14 @@ function makeIntrospectionQuery(
options: {
pgLegacyFunctionsOnly?: boolean,
pgIgnoreRBAC?: boolean,
pgUsePartitionedParent?: boolean,
} = {}
): string {
const { pgLegacyFunctionsOnly = false, pgIgnoreRBAC = true } = options;
const {
pgLegacyFunctionsOnly = false,
pgIgnoreRBAC = true,
pgUsePartitionedParent = false,
} = options;
const unionRBAC = `
union all
select pg_roles.oid _oid, pg_roles.*
Expand Down Expand Up @@ -187,7 +192,11 @@ with
rel.relpersistence in ('p') and
-- We don't want classes that will clash with GraphQL (treat them as private)
rel.relname not like E'\\\\_\\\\_%' and
rel.relkind in ('r', 'v', 'm', 'c', 'f') and
${
pgUsePartitionedParent
? "rel.relkind in ('r', 'v', 'm', 'c', 'f', 'p') and not rel.relispartition"
benjie marked this conversation as resolved.
Show resolved Hide resolved
: "rel.relkind in ('r', 'v', 'm', 'c', 'f')"
} and
($2 is true or not exists(
select 1
from pg_catalog.pg_depend
Expand Down
1 change: 1 addition & 0 deletions packages/postgraphile-core/__tests__/helpers-v5.js
Expand Up @@ -471,6 +471,7 @@ const makeSchema = config => {
ExtendedPlugin,
config.ToyCategoriesPlugin ? ToyCategoriesPlugin : null,
].filter(isNotNullish),
usePartitionedParent: config.usePartitionedParent,
}
);
});
Expand Down
@@ -0,0 +1,14 @@
const core = require("./core");

test(
"prints a schema to test partitioned table-specific features ignoring partition parents and using partitions",
core.test(__filename, ["partitioned"], {
usePartitionedParent: false,
})
);
test(
"prints a schema to test partitioned table-specific features using partition parents and ignoring partitions",
core.test(__filename, ["partitioned"], {
usePartitionedParent: true,
})
);
@@ -0,0 +1,59 @@
{
createWarehouse: {
warehouse: {
id: 1000,
location: "Memphis, TN",
},
},
createItem2: {
item2: {
id: 2000,
description: "Laptop",
},
},
createStock4: {
stock4: {
itemId: 2000,
amount: 10,
warehouseId: 1000,
},
},
updateWarehouseById: {
warehouse: {
id: 1000,
location: "Nashville, TN",
},
},
updateItem2ById: {
item2: {
id: 2000,
description: "TV",
},
},
updateStock4ByItemIdAndWarehouseId: {
stock4: {
itemId: 2000,
amount: 2,
warehouseId: 1000,
},
},
deleteStock4ByItemIdAndWarehouseId: {
stock4: {
itemId: 2000,
amount: 2,
warehouseId: 1000,
},
},
deleteWarehouseById: {
warehouse: {
id: 1000,
location: "Nashville, TN",
},
},
deleteItem2ById: {
item2: {
id: 2000,
description: "TV",
},
},
}