diff --git a/packages/engines/default/DatabaseAnalyser.js b/packages/engines/default/DatabaseAnalyser.js index af3c68d8f..251b49a4f 100644 --- a/packages/engines/default/DatabaseAnalyser.js +++ b/packages/engines/default/DatabaseAnalyser.js @@ -21,9 +21,9 @@ class DatabaseAnalyser { /** @returns {Promise} */ async getModifications() { - if (this.structure != null) throw new Error('DatabaseAnalyse.getModifications - structure must not be filled'); + if (this.structure == null) throw new Error('DatabaseAnalyse.getModifications - structure must be filled'); - return []; + return null; } async fullAnalysis() { @@ -34,6 +34,11 @@ class DatabaseAnalyser { this.structure = structure; this.modifications = await this.getModifications(); + if (this.modifications == null) { + // modifications not implemented, perform full analysis + this.structure = null; + return this._runAnalysis(); + } if (this.modifications.length == 0) return null; console.log('DB modifications detected:', this.modifications); return this._runAnalysis(); diff --git a/packages/engines/mssql/index.js b/packages/engines/mssql/index.js index 2f2f84a32..fcea0209c 100644 --- a/packages/engines/mssql/index.js +++ b/packages/engines/mssql/index.js @@ -109,11 +109,11 @@ const driver = { }, async analyseFull(pool) { const analyser = new MsSqlAnalyser(pool, this); - return await analyser.fullAnalysis(); + return analyser.fullAnalysis(); }, async analyseIncremental(pool, structure) { const analyser = new MsSqlAnalyser(pool, this); - return await analyser.incrementalAnalysis(structure); + return analyser.incrementalAnalysis(structure); }, createDumper() { return new MsSqlDumper(this); diff --git a/packages/engines/mysql/MySqlAnalyser.js b/packages/engines/mysql/MySqlAnalyser.js index 995d22028..bcf9cd1ff 100644 --- a/packages/engines/mysql/MySqlAnalyser.js +++ b/packages/engines/mysql/MySqlAnalyser.js @@ -15,25 +15,27 @@ class MySqlAnalyser extends DatabaseAnalayser { res = res.replace('#DATABASE#', this.pool._database_name); return res; } - async runAnalysis() { + async _runAnalysis() { const tables = await this.driver.query(this.pool, this.createQuery('tables')); const columns = await this.driver.query(this.pool, this.createQuery('columns')); // const pkColumns = await this.driver.query(this.pool, this.createQuery('primary_keys.sql')); // const fkColumns = await this.driver.query(this.pool, this.createQuery('foreign_keys.sql')); - this.result.tables = tables.rows.map((table) => ({ - ...table, - columns: columns.rows - .filter((col) => col.pureName == table.pureName) - .map(({ isNullable, extra, ...col }) => ({ - ...col, - notNull: !isNullable, - autoIncrement: extra && extra.toLowerCase().includes('auto_increment'), - })), - foreignKeys: [], - // primaryKey: extractPrimaryKeys(table, pkColumns.rows), - // foreignKeys: extractForeignKeys(table, fkColumns.rows), - })); + return this.mergeAnalyseResult({ + tables: tables.rows.map((table) => ({ + ...table, + columns: columns.rows + .filter((col) => col.pureName == table.pureName) + .map(({ isNullable, extra, ...col }) => ({ + ...col, + notNull: !isNullable, + autoIncrement: extra && extra.toLowerCase().includes('auto_increment'), + })), + foreignKeys: [], + // primaryKey: extractPrimaryKeys(table, pkColumns.rows), + // foreignKeys: extractForeignKeys(table, fkColumns.rows), + })), + }); } } diff --git a/packages/engines/mysql/index.js b/packages/engines/mysql/index.js index 4962d452f..670ae9bc4 100644 --- a/packages/engines/mysql/index.js +++ b/packages/engines/mysql/index.js @@ -42,8 +42,11 @@ const driver = { }, async analyseFull(pool) { const analyser = new MySqlAnalyser(pool, this); - await analyser.runAnalysis(); - return analyser.result; + return analyser.fullAnalysis(); + }, + async analyseIncremental(pool, structure) { + const analyser = new MySqlAnalyser(pool, this); + return analyser.incrementalAnalysis(structure); }, async listDatabases(connection) { const { rows } = await this.query(connection, "show databases"); diff --git a/packages/engines/postgres/PostgreAnalyser.js b/packages/engines/postgres/PostgreAnalyser.js index 007bff8da..4c0436e54 100644 --- a/packages/engines/postgres/PostgreAnalyser.js +++ b/packages/engines/postgres/PostgreAnalyser.js @@ -14,24 +14,26 @@ class MySqlAnalyser extends DatabaseAnalayser { res = res.replace('=[OBJECT_ID_CONDITION]', ' is not null'); return res; } - async runAnalysis() { + async _runAnalysis() { const tables = await this.driver.query(this.pool, this.createQuery('tableModifications')); const columns = await this.driver.query(this.pool, this.createQuery('columns')); // const pkColumns = await this.driver.query(this.pool, this.createQuery('primary_keys.sql')); // const fkColumns = await this.driver.query(this.pool, this.createQuery('foreign_keys.sql')); - this.result.tables = tables.rows.map((table) => ({ - ...table, - columns: columns.rows - .filter((col) => col.pureName == table.pureName && col.schemaName == table.schemaName) - .map(({ isNullable, ...col }) => ({ - ...col, - notNull: !isNullable, - })), - foreignKeys: [], - // primaryKey: extractPrimaryKeys(table, pkColumns.rows), - // foreignKeys: extractForeignKeys(table, fkColumns.rows), - })); + return this.mergeAnalyseResult({ + tables: tables.rows.map((table) => ({ + ...table, + columns: columns.rows + .filter((col) => col.pureName == table.pureName && col.schemaName == table.schemaName) + .map(({ isNullable, ...col }) => ({ + ...col, + notNull: !isNullable, + })), + foreignKeys: [], + // primaryKey: extractPrimaryKeys(table, pkColumns.rows), + // foreignKeys: extractForeignKeys(table, fkColumns.rows), + })), + }); } } diff --git a/packages/engines/postgres/index.js b/packages/engines/postgres/index.js index b1aa3c6a3..df55521c1 100644 --- a/packages/engines/postgres/index.js +++ b/packages/engines/postgres/index.js @@ -29,8 +29,11 @@ const driver = { }, async analyseFull(pool) { const analyser = new PostgreAnalyser(pool, this); - await analyser.runAnalysis(); - return analyser.result; + return analyser.fullAnalysis(); + }, + async analyseIncremental(pool, structure) { + const analyser = new PostgreAnalyser(pool, this); + return analyser.incrementalAnalysis(structure); }, createDumper() { return new PostgreDumper(this); diff --git a/packages/types/dbinfo.d.ts b/packages/types/dbinfo.d.ts index d0a8a5efe..e8b280b3a 100644 --- a/packages/types/dbinfo.d.ts +++ b/packages/types/dbinfo.d.ts @@ -1,4 +1,4 @@ -import { DbType } from './DbType'; +import { DbType } from './dbtypes'; export interface NamedObjectInfo { pureName: string;