fixes
Some checks failed
Run tests / test-runner (push) Has been cancelled

This commit is contained in:
SPRINX0\prochazka 2024-11-12 17:38:18 +01:00
parent 59aa2e3f33
commit c6dab85fc2
3 changed files with 14 additions and 5 deletions

View File

@ -4,6 +4,7 @@ const { ScriptDrivedDeployer } = require('dbgate-datalib');
const connectUtility = require('../utility/connectUtility');
const requireEngineDriver = require('../utility/requireEngineDriver');
const loadModelFolder = require('../utility/loadModelFolder');
const crypto = require('crypto');
async function deployDb({
connection,
@ -24,7 +25,8 @@ async function deployDb({
const scriptDeployer = new ScriptDrivedDeployer(
dbhan,
driver,
loadedDbModel ?? (await loadModelFolder(modelFolder))
Array.isArray(loadedDbModel) ? loadedDbModel : modelFolder ? await loadModelFolder(modelFolder) : [],
crypto
);
await scriptDeployer.runPre();

View File

@ -1,6 +1,5 @@
import { DatabaseModelFile, extractErrorLogData, getLogger, runCommandOnDriver, runQueryOnDriver } from 'dbgate-tools';
import { EngineDriver } from 'dbgate-types';
import crypto from 'crypto';
import _sortBy from 'lodash/sortBy';
const logger = getLogger('ScriptDrivedDeployer');
@ -24,7 +23,7 @@ export class ScriptDrivedDeployer {
journalItems: DeployScriptJournalItem[] = [];
constructor(public dbhan: any, public driver: EngineDriver, public files: DatabaseModelFile[]) {
constructor(public dbhan: any, public driver: EngineDriver, public files: DatabaseModelFile[], public crypto: any) {
this.predeploy = files.filter(x => x.name.endsWith('.predeploy.sql'));
this.uninstall = files.filter(x => x.name.endsWith('.uninstall.sql'));
this.install = files.filter(x => x.name.endsWith('.install.sql'));
@ -145,7 +144,7 @@ export class ScriptDrivedDeployer {
}
async runFile(file: DatabaseModelFile, category: string) {
const hash = crypto.createHash('md5').update(file.text.trim()).digest('hex');
const hash = this.crypto.createHash('md5').update(file.text.trim()).digest('hex');
const journalItem = this.journalItems.find(x => x.name == file.name);
const isEqual = journalItem && journalItem.script_hash == hash;
@ -166,7 +165,7 @@ export class ScriptDrivedDeployer {
await this.runFileCore(
uninstallFile,
'uninstall',
crypto.createHash('md5').update(uninstallFile.text.trim()).digest('hex')
this.crypto.createHash('md5').update(uninstallFile.text.trim()).digest('hex')
);
}
await this.runFileCore(file, category, hash);

View File

@ -312,6 +312,14 @@ export function safeJsonParse(json, defaultValue?, logError = false) {
}
}
export function safeCompileRegExp(regex: string, flags: string) {
try {
return new RegExp(regex, flags);
} catch (err) {
return null;
}
}
export function shouldOpenMultilineDialog(value) {
if (_isString(value)) {
if (value.includes('\n')) {