mysql - analyse views, procedures, functions

This commit is contained in:
Jan Prochazka 2020-06-28 13:58:56 +02:00
parent dc4fbe21de
commit 536ee6678f
5 changed files with 28 additions and 1 deletions

View File

@ -44,6 +44,8 @@ class MySqlAnalyser extends DatabaseAnalayser {
const columns = await this.driver.query(this.pool, this.createQuery('columns'));
const pkColumns = await this.driver.query(this.pool, this.createQuery('primaryKeys'));
const fkColumns = await this.driver.query(this.pool, this.createQuery('foreignKeys'));
const views = await this.driver.query(this.pool, this.createQuery('views'));
const programmables = await this.driver.query(this.pool, this.createQuery('programmables'));
return this.mergeAnalyseResult({
tables: tables.rows.map((table) => ({
@ -52,6 +54,12 @@ class MySqlAnalyser extends DatabaseAnalayser {
primaryKey: DatabaseAnalayser.extractPrimaryKeys(table, pkColumns.rows),
foreignKeys: DatabaseAnalayser.extractForeignKeys(table, fkColumns.rows),
})),
views: views.rows.map((view) => ({
...view,
columns: columns.rows.filter((col) => col.pureName == view.pureName).map(getColumnInfo),
})),
procedures: programmables.rows.filter((x) => x.objectType == 'PROCEDURE').map(fp.omit(['objectType'])),
functions: programmables.rows.filter((x) => x.objectType == 'FUNCTION').map(fp.omit(['objectType'])),
});
}
}

View File

@ -3,6 +3,8 @@ const tables = require('./tables');
const primaryKeys = require('./primaryKeys');
const foreignKeys = require('./foreignKeys');
const tableModifications = require('./tableModifications');
const views = require('./views');
const programmables = require('./programmables');
module.exports = {
columns,
@ -10,4 +12,6 @@ module.exports = {
primaryKeys,
foreignKeys,
tableModifications,
views,
programmables,
};

View File

@ -0,0 +1,8 @@
module.exports = `
select
ROUTINE_NAME as pureName,
ROUTINE_TYPE as objectType,
ROUTINE_DEFINITION as createSql
from information_schema.routines
where ROUTINE_SCHEMA = '#DATABASE#'
`;

View File

@ -3,5 +3,5 @@ select
TABLE_NAME as pureName,
case when ENGINE='InnoDB' then CREATE_TIME else coalesce(UPDATE_TIME, CREATE_TIME) end as alterTime
from information_schema.tables
where TABLE_SCHEMA = '#DATABASE#' and TABLE_NAME =[OBJECT_NAME_CONDITION];
where TABLE_SCHEMA = '#DATABASE#' and TABLE_TYPE='BASE TABLE' and TABLE_NAME =[OBJECT_NAME_CONDITION];
`;

View File

@ -0,0 +1,7 @@
module.exports = `
select
TABLE_NAME as pureName,
VIEW_DEFINITION as createSql
from information_schema.views
where TABLE_SCHEMA = '#DATABASE#' and TABLE_NAME =[OBJECT_NAME_CONDITION];
`;