Skip to content

Commit 9d524f0

Browse files
committed
RE: removed showing partitions in treeView, added checkbox to include partitions
1 parent 567f57a commit 9d524f0

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

reverse_engineering/api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ module.exports = {
129129
schemaName,
130130
collections[schemaName],
131131
data.recordSamplingSettings,
132+
data.includePartitions,
132133
);
133134
const { functions, procedures } = await postgresService.retrieveFunctionsWithProcedures(schemaName);
134135

reverse_engineering/config.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,12 @@
1414
"port",
1515
"userName"
1616
],
17-
"helpUrl": "https://hackolade.com/help/ConnecttoaPostgreSQLinstance.html"
17+
"helpUrl": "https://hackolade.com/help/ConnecttoaPostgreSQLinstance.html",
18+
"options": [
19+
{
20+
"inputLabel": "Include partitions",
21+
"inputTooltip": "Reverse-engineer all partitions as tables",
22+
"inputKeyword": "includePartitions"
23+
}
24+
]
1825
}

reverse_engineering/helpers/postgresService.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,21 @@ module.exports = {
140140
});
141141
},
142142

143-
async retrieveEntitiesData(schemaName, entitiesNames, recordSamplingSettings) {
143+
async retrieveEntitiesData(schemaName, entitiesNames, recordSamplingSettings, includePartitions = false) {
144144
const userDefinedTypes = await this._retrieveUserDefinedTypes(schemaName);
145145
const schemaOidResult = await db.queryTolerant(queryConstants.GET_NAMESPACE_OID, [schemaName], true);
146146
const schemaOid = schemaOidResult?.oid;
147+
const partitions = includePartitions ? await db.queryTolerant(queryConstants.GET_PARTITIONS, [schemaOid]) : [];
147148

148149
const [viewsNames, tablesNames] = _.partition(entitiesNames, isViewByName);
149150

151+
const allTablesList = tablesNames.flatMap(tableName => [
152+
tableName,
153+
..._.filter(partitions, { parent_name: tableName }).map(({ child_name }) => child_name),
154+
]);
155+
150156
const tables = await mapPromises(
151-
tablesNames,
157+
allTablesList,
152158
_.bind(
153159
this._retrieveSingleTableData,
154160
this,
@@ -172,9 +178,7 @@ module.exports = {
172178
const functionsWithProcedures = await db.queryTolerant(queryConstants.GET_FUNCTIONS_WITH_PROCEDURES, [
173179
schemaName,
174180
]);
175-
const functionAdditionalData = await db.queryTolerant(getGetFunctionsAdditionalDataQuery(version), [
176-
schemaOid,
177-
]);
181+
const functionAdditionalData = await db.queryTolerant(getGetFunctionsAdditionalDataQuery(version), [schemaOid]);
178182
const [functions, procedures] = _.partition(_.filter(functionsWithProcedures, 'routine_type'), {
179183
routine_type: 'FUNCTION',
180184
});

reverse_engineering/helpers/queryConstants.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,19 @@ const queryConstants = {
9797
GET_VERSION_AS_NUM: 'SHOW server_version_num;',
9898
GET_SCHEMA_NAMES: 'SELECT schema_name FROM information_schema.schemata;',
9999
GET_TABLE_NAMES: `
100-
SELECT table_name, table_type
101-
FROM information_schema.tables
102-
WHERE table_schema = $1
103-
ORDER BY table_name;`,
100+
SELECT tables.table_name, tables.table_type FROM information_schema.tables AS tables
101+
INNER JOIN
102+
(SELECT
103+
pg_class.relname AS table_name,
104+
pg_namespace.nspname AS table_schema
105+
FROM pg_catalog.pg_class AS pg_class
106+
INNER JOIN pg_catalog.pg_namespace AS pg_namespace
107+
ON (pg_namespace.oid = pg_class.relnamespace)
108+
WHERE pg_class.relispartition = false
109+
AND pg_class.relkind = ANY('{"r","v","t","m","p"}'))
110+
AS catalog_table_data
111+
ON (catalog_table_data.table_name = tables.table_name AND catalog_table_data.table_schema = tables.table_schema)
112+
WHERE tables.table_schema = $1;`,
104113
GET_NAMESPACE_OID: 'SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = $1',
105114
GET_TABLE_LEVEL_DATA: `
106115
SELECT pc.oid, pc.relpersistence, pc.reloptions, pt.spcname
@@ -267,6 +276,15 @@ const queryConstants = {
267276
WHERE pg_type.typname = $1 AND pg_namespace.nspname = $2 AND pg_constraint.contype = 'c';`,
268277
GET_DATABASES:
269278
'SELECT datname AS database_name FROM pg_catalog.pg_database WHERE datistemplate != TRUE AND datallowconn = TRUE;',
279+
GET_PARTITIONS: `
280+
SELECT
281+
inher_child.relname AS child_name,
282+
inher_parent.relname AS parent_name
283+
FROM pg_inherits
284+
LEFT JOIN pg_class AS inher_child ON (inher_child.oid = pg_inherits.inhrelid)
285+
LEFT JOIN pg_class AS inher_parent ON (inher_parent.oid = pg_inherits.inhparent)
286+
WHERE inher_parent.relkind = 'p'
287+
AND inher_parent.relnamespace = $1;`,
270288
};
271289

272290
const getQueryName = query => {

0 commit comments

Comments
 (0)