fix(clean): refs #5123 handle numbers with more than one name
This commit is contained in:
parent
7208a8284f
commit
9ab0c0b09c
32
myt-clean.js
32
myt-clean.js
|
@ -28,13 +28,13 @@ class Clean extends Command {
|
||||||
|
|
||||||
async run(myt, opts) {
|
async run(myt, opts) {
|
||||||
const conn = await myt.dbConnect();
|
const conn = await myt.dbConnect();
|
||||||
const versionDirs = await fs.readdir(opts.versionsDir);
|
|
||||||
const archiveDir = path.join(opts.versionsDir, '.archive');
|
const archiveDir = path.join(opts.versionsDir, '.archive');
|
||||||
|
|
||||||
const dbVersion = await myt.fetchDbVersion() || {};
|
const dbVersion = await myt.fetchDbVersion() || {};
|
||||||
const number = parseInt(dbVersion.number);
|
const number = parseInt(dbVersion.number);
|
||||||
|
|
||||||
const oldVersions = [];
|
const oldVersions = [];
|
||||||
|
const versionDirs = await fs.readdir(opts.versionsDir);
|
||||||
for (const versionDir of versionDirs) {
|
for (const versionDir of versionDirs) {
|
||||||
const version = await myt.loadVersion(versionDir);
|
const version = await myt.loadVersion(versionDir);
|
||||||
const shouldArchive = version
|
const shouldArchive = version
|
||||||
|
@ -71,9 +71,9 @@ class Clean extends Command {
|
||||||
await fs.rmdir(srcDir);
|
await fs.rmdir(srcDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Old versions archived: ${oldVersions.length}`);
|
console.log(` -> ${oldVersions.length} versions archived.`);
|
||||||
} else
|
} else
|
||||||
console.log(`No versions to archive.`);
|
console.log(` -> No versions archived.`);
|
||||||
|
|
||||||
if (opts.purge) {
|
if (opts.purge) {
|
||||||
const versionDb = new VersionDb(myt, opts.versionsDir);
|
const versionDb = new VersionDb(myt, opts.versionsDir);
|
||||||
|
@ -89,6 +89,7 @@ class Clean extends Command {
|
||||||
[opts.code]
|
[opts.code]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let nPurged = 0;
|
||||||
for (const script of res) {
|
for (const script of res) {
|
||||||
const hasVersion = await versionDb.hasScript(script);
|
const hasVersion = await versionDb.hasScript(script);
|
||||||
const hasArchive = await archiveDb.hasScript(script);
|
const hasArchive = await archiveDb.hasScript(script);
|
||||||
|
@ -99,8 +100,14 @@ class Clean extends Command {
|
||||||
WHERE code = ? AND number = ? AND file = ?`,
|
WHERE code = ? AND number = ? AND file = ?`,
|
||||||
[opts.code, script.number, script.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() {
|
async load() {
|
||||||
const versionMap = this.versionMap = new Map();
|
const map = this.map = new Map();
|
||||||
if (await fs.pathExists(this.baseDir)) {
|
if (await fs.pathExists(this.baseDir)) {
|
||||||
const dirs = await fs.readdir(this.baseDir);
|
const dirs = await fs.readdir(this.baseDir);
|
||||||
for (const dir of dirs) {
|
for (const dir of dirs) {
|
||||||
const version = this.myt.parseVersionDir(dir);
|
const version = this.myt.parseVersionDir(dir);
|
||||||
if (!version) continue;
|
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) {
|
async hasScript(script) {
|
||||||
const dir = this.versionMap.get(script.number);
|
const dirs = this.map.get(script.number);
|
||||||
if (!dir) return false;
|
if (dirs)
|
||||||
const scriptPath = path.join(this.baseDir, dir, script.file);
|
for (const dir of dirs) {
|
||||||
return await fs.pathExists(scriptPath);
|
const scriptPath = path.join(this.baseDir, dir, script.file);
|
||||||
|
if (await fs.pathExists(scriptPath)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
myt-push.js
12
myt-push.js
|
@ -138,6 +138,7 @@ class Push extends Command {
|
||||||
|
|
||||||
console.log('Applying versions.');
|
console.log('Applying versions.');
|
||||||
|
|
||||||
|
let nVersions = 0;
|
||||||
let nChanges = 0;
|
let nChanges = 0;
|
||||||
let silent = true;
|
let silent = true;
|
||||||
const versionsDir = opts.versionsDir;
|
const versionsDir = opts.versionsDir;
|
||||||
|
@ -191,7 +192,6 @@ class Push extends Command {
|
||||||
|
|
||||||
const action = apply ? 'apply' : 'ignore';
|
const action = apply ? 'apply' : 'ignore';
|
||||||
logVersion(`[${version.number}]`.cyan, version.name, action);
|
logVersion(`[${version.number}]`.cyan, version.name, action);
|
||||||
|
|
||||||
if (!apply) continue;
|
if (!apply) continue;
|
||||||
|
|
||||||
for (const script of version.scripts) {
|
for (const script of version.scripts) {
|
||||||
|
@ -243,9 +243,15 @@ class Push extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.updateVersion('number', version.number);
|
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
|
// Apply routines
|
||||||
|
|
||||||
console.log('Applying changed routines.');
|
console.log('Applying changed routines.');
|
||||||
|
@ -381,8 +387,8 @@ class Push extends Command {
|
||||||
|
|
||||||
await finalize();
|
await finalize();
|
||||||
|
|
||||||
if (nRoutines > 0) {
|
if (nRoutines) {
|
||||||
console.log(` -> ${nRoutines} routines have changed.`);
|
console.log(` -> ${nRoutines} routines changed.`);
|
||||||
} else
|
} else
|
||||||
console.log(` -> No routines changed.`);
|
console.log(` -> No routines changed.`);
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@verdnatura/myt",
|
"name": "@verdnatura/myt",
|
||||||
"version": "1.5.26",
|
"version": "1.5.27",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@verdnatura/myt",
|
"name": "@verdnatura/myt",
|
||||||
"version": "1.5.26",
|
"version": "1.5.27",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sqltools/formatter": "^1.2.5",
|
"@sqltools/formatter": "^1.2.5",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@verdnatura/myt",
|
"name": "@verdnatura/myt",
|
||||||
"version": "1.5.26",
|
"version": "1.5.27",
|
||||||
"author": "Verdnatura Levante SL",
|
"author": "Verdnatura Levante SL",
|
||||||
"description": "MySQL version control",
|
"description": "MySQL version control",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
|
|
Loading…
Reference in New Issue