From 9ab0c0b09cba44f37e0497bbed0fb3cd35553b93 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 19 Jan 2024 10:16:47 +0100 Subject: [PATCH] fix(clean): refs #5123 handle numbers with more than one name --- myt-clean.js | 32 ++++++++++++++++++++++---------- myt-push.js | 12 +++++++++--- package-lock.json | 4 ++-- package.json | 2 +- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/myt-clean.js b/myt-clean.js index 825f003..fed9bc1 100644 --- a/myt-clean.js +++ b/myt-clean.js @@ -28,13 +28,13 @@ class Clean extends Command { async run(myt, opts) { const conn = await myt.dbConnect(); - const versionDirs = await fs.readdir(opts.versionsDir); const archiveDir = path.join(opts.versionsDir, '.archive'); const dbVersion = await myt.fetchDbVersion() || {}; const number = parseInt(dbVersion.number); const oldVersions = []; + const versionDirs = await fs.readdir(opts.versionsDir); for (const versionDir of versionDirs) { const version = await myt.loadVersion(versionDir); const shouldArchive = version @@ -71,9 +71,9 @@ class Clean extends Command { await fs.rmdir(srcDir); } - console.log(`Old versions archived: ${oldVersions.length}`); + console.log(` -> ${oldVersions.length} versions archived.`); } else - console.log(`No versions to archive.`); + console.log(` -> No versions archived.`); if (opts.purge) { const versionDb = new VersionDb(myt, opts.versionsDir); @@ -89,6 +89,7 @@ class Clean extends Command { [opts.code] ); + let nPurged = 0; for (const script of res) { const hasVersion = await versionDb.hasScript(script); const hasArchive = await archiveDb.hasScript(script); @@ -99,8 +100,14 @@ class Clean extends Command { WHERE code = ? AND number = ? AND file = ?`, [opts.code, script.number, script.file] ); + nPurged++; } } + + if (nPurged) + console.log(` -> ${nPurged} versions purged from log.`); + else + console.log(` -> No versions purged from log.`); } } } @@ -111,23 +118,28 @@ class VersionDb { } async load() { - const versionMap = this.versionMap = new Map(); + const map = this.map = new Map(); if (await fs.pathExists(this.baseDir)) { const dirs = await fs.readdir(this.baseDir); for (const dir of dirs) { const version = this.myt.parseVersionDir(dir); if (!version) continue; - versionMap.set(version.number, dir); + let subdirs = map.get(version.number); + if (!subdirs) map.set(version.number, subdirs = []); + subdirs.push(dir); } } - return versionMap; + return map; } async hasScript(script) { - const dir = this.versionMap.get(script.number); - if (!dir) return false; - const scriptPath = path.join(this.baseDir, dir, script.file); - return await fs.pathExists(scriptPath); + const dirs = this.map.get(script.number); + if (dirs) + for (const dir of dirs) { + const scriptPath = path.join(this.baseDir, dir, script.file); + if (await fs.pathExists(scriptPath)) return true; + } + return false; } } diff --git a/myt-push.js b/myt-push.js index 664b606..c0fac46 100644 --- a/myt-push.js +++ b/myt-push.js @@ -138,6 +138,7 @@ class Push extends Command { console.log('Applying versions.'); + let nVersions = 0; let nChanges = 0; let silent = true; const versionsDir = opts.versionsDir; @@ -191,7 +192,6 @@ class Push extends Command { const action = apply ? 'apply' : 'ignore'; logVersion(`[${version.number}]`.cyan, version.name, action); - if (!apply) continue; for (const script of version.scripts) { @@ -243,9 +243,15 @@ class Push extends Command { } await this.updateVersion('number', version.number); + nVersions++; } } + if (nVersions) { + console.log(` -> ${nVersions} versions with ${nChanges} changes applied.`); + } else + console.log(` -> No versions applied.`); + // Apply routines console.log('Applying changed routines.'); @@ -381,8 +387,8 @@ class Push extends Command { await finalize(); - if (nRoutines > 0) { - console.log(` -> ${nRoutines} routines have changed.`); + if (nRoutines) { + console.log(` -> ${nRoutines} routines changed.`); } else console.log(` -> No routines changed.`); diff --git a/package-lock.json b/package-lock.json index 65e2ce1..638072a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@verdnatura/myt", - "version": "1.5.26", + "version": "1.5.27", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@verdnatura/myt", - "version": "1.5.26", + "version": "1.5.27", "license": "GPL-3.0", "dependencies": { "@sqltools/formatter": "^1.2.5", diff --git a/package.json b/package.json index af019fd..069f070 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@verdnatura/myt", - "version": "1.5.26", + "version": "1.5.27", "author": "Verdnatura Levante SL", "description": "MySQL version control", "license": "GPL-3.0",