clickhouse - view support, incremental structure update

This commit is contained in:
Jan Prochazka 2024-09-12 13:49:10 +02:00
parent d2e49967e4
commit e21c6d4872
5 changed files with 41 additions and 1 deletions

View File

@ -33,6 +33,8 @@ class Analyser extends DatabaseAnalyser {
const tables = await this.analyserQuery('tables', ['tables']);
this.feedback({ analysingMessage: 'Loading columns' });
const columns = await this.analyserQuery('columns', ['tables', 'views']);
this.feedback({ analysingMessage: 'Loading views' });
const views = await this.analyserQuery('views', ['views']);
const res = {
tables: tables.rows.map((table) => ({
@ -53,10 +55,29 @@ class Analyser extends DatabaseAnalyser {
: null,
foreignKeys: [],
})),
views: views.rows.map((view) => ({
...view,
columns: columns.rows
.filter((col) => col.pureName == view.pureName)
.map((col) => ({
...col,
...extractDataType(col.dataType),
})),
createSql: `CREATE VIEW "${view.pureName}"\nAS\n${view.viewDefinition}`,
})),
};
this.feedback({ analysingMessage: null });
return res;
}
async _getFastSnapshot() {
const tableModificationsQueryData = await this.analyserQuery('tableModifications');
return {
tables: tableModificationsQueryData.rows.filter((x) => x.tableEngine != 'View'),
views: tableModificationsQueryData.rows.filter((x) => x.tableEngine == 'View'),
};
}
}
module.exports = Analyser;

View File

@ -1,7 +1,11 @@
const columns = require('./columns');
const tables = require('./tables');
const views = require('./views');
const tableModifications = require('./tableModifications');
module.exports = {
columns,
tables,
views,
tableModifications,
};

View File

@ -0,0 +1,5 @@
module.exports = `
select metadata_modification_time as "contentHash", uuid as "objectId", engine as "tableEngine"
from system.tables
where database='#DATABASE#';
`;

View File

@ -2,5 +2,5 @@ module.exports = `
select name as "pureName", metadata_modification_time as "contentHash", total_rows as "tableRowCount", uuid as "objectId", comment as "objectComment",
engine as "tableEngine", primary_key as "primaryKeyColumns", sorting_key as "sortingKeyColumns"
from system.tables
where database='#DATABASE#' and uuid =OBJECT_ID_CONDITION;
where database='#DATABASE#' and uuid =OBJECT_ID_CONDITION and engine != 'View';
`;

View File

@ -0,0 +1,10 @@
module.exports = `
select
tables.name as "pureName",
tables.uuid as "objectId",
views.view_definition as "viewDefinition",
tables.metadata_modification_time as "contentHash"
from information_schema.views
inner join system.tables on views.table_name = tables.name and views.table_schema = tables.database
where views.table_schema='#DATABASE#' and tables.uuid =OBJECT_ID_CONDITION
`;