diff --git a/packages/engines/mysql/MySqlAnalyser.js b/packages/engines/mysql/MySqlAnalyser.js index 6cab911c..abca6d1c 100644 --- a/packages/engines/mysql/MySqlAnalyser.js +++ b/packages/engines/mysql/MySqlAnalyser.js @@ -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'])), }); } } diff --git a/packages/engines/mysql/sql/index.js b/packages/engines/mysql/sql/index.js index ac18120c..3bf884ad 100644 --- a/packages/engines/mysql/sql/index.js +++ b/packages/engines/mysql/sql/index.js @@ -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, }; diff --git a/packages/engines/mysql/sql/programmables.js b/packages/engines/mysql/sql/programmables.js new file mode 100644 index 00000000..ea702a92 --- /dev/null +++ b/packages/engines/mysql/sql/programmables.js @@ -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#' +`; diff --git a/packages/engines/mysql/sql/tables.js b/packages/engines/mysql/sql/tables.js index 3d7d7299..38b2d974 100644 --- a/packages/engines/mysql/sql/tables.js +++ b/packages/engines/mysql/sql/tables.js @@ -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]; `; diff --git a/packages/engines/mysql/sql/views.js b/packages/engines/mysql/sql/views.js new file mode 100644 index 00000000..0c34a0df --- /dev/null +++ b/packages/engines/mysql/sql/views.js @@ -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]; +`;