Fixed separate schema mode, more logging #894

This commit is contained in:
Jan Prochazka
2024-09-26 08:12:51 +02:00
parent 61a9f02899
commit 7a5abb5f47
3 changed files with 26 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
const stableStringify = require('json-stable-stringify'); const stableStringify = require('json-stable-stringify');
const { splitQuery } = require('dbgate-query-splitter'); const { splitQuery } = require('dbgate-query-splitter');
const childProcessChecker = require('../utility/childProcessChecker'); const childProcessChecker = require('../utility/childProcessChecker');
const { extractBoolSettingsValue, extractIntSettingsValue, getLogger, isCompositeDbName } = require('dbgate-tools'); const { extractBoolSettingsValue, extractIntSettingsValue, getLogger, isCompositeDbName, dbNameLogCategory } = require('dbgate-tools');
const requireEngineDriver = require('../utility/requireEngineDriver'); const requireEngineDriver = require('../utility/requireEngineDriver');
const connectUtility = require('../utility/connectUtility'); const connectUtility = require('../utility/connectUtility');
const { handleProcessCommunication } = require('../utility/processComm'); const { handleProcessCommunication } = require('../utility/processComm');
@@ -46,6 +46,12 @@ async function checkedAsyncCall(promise) {
let loadingModel = false; let loadingModel = false;
async function handleFullRefresh() { async function handleFullRefresh() {
if (storedConnection.useSeparateSchemas && !isCompositeDbName(dbhan?.database)) {
resolveAnalysedPromises();
// skip loading DB structure
return;
}
loadingModel = true; loadingModel = true;
const driver = requireEngineDriver(storedConnection); const driver = requireEngineDriver(storedConnection);
setStatusName('loadStructure'); setStatusName('loadStructure');
@@ -60,6 +66,11 @@ async function handleFullRefresh() {
} }
async function handleIncrementalRefresh(forceSend) { async function handleIncrementalRefresh(forceSend) {
if (storedConnection.useSeparateSchemas && !isCompositeDbName(dbhan?.database)) {
resolveAnalysedPromises();
// skip loading DB structure
return;
}
loadingModel = true; loadingModel = true;
const driver = requireEngineDriver(storedConnection); const driver = requireEngineDriver(storedConnection);
setStatusName('checkStructure'); setStatusName('checkStructure');
@@ -117,7 +128,7 @@ async function handleConnect({ connection, structure, globalSettings }) {
logger.debug( logger.debug(
`Connected to database, driver: ${storedConnection.engine}, separate schemas: ${ `Connected to database, driver: ${storedConnection.engine}, separate schemas: ${
storedConnection.useSeparateSchemas ? 'YES' : 'NO' storedConnection.useSeparateSchemas ? 'YES' : 'NO'
}, 'DB: ${isCompositeDbName(dbhan.database) ? 'composite' : dbhan.database ? 'simple' : 'NO'} }` }, 'DB: ${dbNameLogCategory(dbhan.database)} }`
); );
dbhan.feedback = feedback => setStatus({ feedback }); dbhan.feedback = feedback => setStatus({ feedback });
await checkedAsyncCall(readVersion()); await checkedAsyncCall(readVersion());

View File

@@ -5,7 +5,7 @@ import _pick from 'lodash/pick';
import _compact from 'lodash/compact'; import _compact from 'lodash/compact';
import { getLogger } from './getLogger'; import { getLogger } from './getLogger';
import { type Logger } from 'pinomin'; import { type Logger } from 'pinomin';
import { isCompositeDbName, splitCompositeDbName } from './schemaInfoTools'; import { dbNameLogCategory, isCompositeDbName, splitCompositeDbName } from './schemaInfoTools';
const logger = getLogger('dbAnalyser'); const logger = getLogger('dbAnalyser');
@@ -69,6 +69,7 @@ export class DatabaseAnalyser {
} }
async fullAnalysis() { async fullAnalysis() {
logger.info(`Performing full analysis, DB=${dbNameLogCategory(this.dbhan.database)}, engine=${this.driver.engine}`);
const res = this.addEngineField(await this._runAnalysis()); const res = this.addEngineField(await this._runAnalysis());
// console.log('FULL ANALYSIS', res); // console.log('FULL ANALYSIS', res);
return res; return res;
@@ -89,6 +90,7 @@ export class DatabaseAnalyser {
} }
async incrementalAnalysis(structure) { async incrementalAnalysis(structure) {
logger.info(`Performing incremental analysis, DB=${dbNameLogCategory(this.dbhan.database)}, engine=${this.driver.engine}`);
this.structure = structure; this.structure = structure;
const modifications = await this.getModifications(); const modifications = await this.getModifications();

View File

@@ -36,3 +36,13 @@ export function extractDbNameFromComposite(name: string) {
export function extractSchemaNameFromComposite(name: string) { export function extractSchemaNameFromComposite(name: string) {
return splitCompositeDbName(name)?.schema; return splitCompositeDbName(name)?.schema;
} }
export function dbNameLogCategory(database: string): string {
if (isCompositeDbName(database)) {
return '~composite';
}
if (database) {
return '~simple';
}
return '~nodb';
}