@verdnatura/myt 1.5.26 → 1.5.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/myt-clean.js CHANGED
@@ -28,13 +28,13 @@ class Clean extends Command {
28
28
 
29
29
  async run(myt, opts) {
30
30
  const conn = await myt.dbConnect();
31
- const versionDirs = await fs.readdir(opts.versionsDir);
32
31
  const archiveDir = path.join(opts.versionsDir, '.archive');
33
32
 
34
33
  const dbVersion = await myt.fetchDbVersion() || {};
35
34
  const number = parseInt(dbVersion.number);
36
35
 
37
36
  const oldVersions = [];
37
+ const versionDirs = await fs.readdir(opts.versionsDir);
38
38
  for (const versionDir of versionDirs) {
39
39
  const version = await myt.loadVersion(versionDir);
40
40
  const shouldArchive = version
@@ -71,9 +71,9 @@ class Clean extends Command {
71
71
  await fs.rmdir(srcDir);
72
72
  }
73
73
 
74
- console.log(`Old versions archived: ${oldVersions.length}`);
74
+ console.log(` -> ${oldVersions.length} versions archived.`);
75
75
  } else
76
- console.log(`No versions to archive.`);
76
+ console.log(` -> No versions archived.`);
77
77
 
78
78
  if (opts.purge) {
79
79
  const versionDb = new VersionDb(myt, opts.versionsDir);
@@ -89,6 +89,7 @@ class Clean extends Command {
89
89
  [opts.code]
90
90
  );
91
91
 
92
+ let nPurged = 0;
92
93
  for (const script of res) {
93
94
  const hasVersion = await versionDb.hasScript(script);
94
95
  const hasArchive = await archiveDb.hasScript(script);
@@ -99,8 +100,14 @@ class Clean extends Command {
99
100
  WHERE code = ? AND number = ? AND file = ?`,
100
101
  [opts.code, script.number, script.file]
101
102
  );
103
+ nPurged++;
102
104
  }
103
105
  }
106
+
107
+ if (nPurged)
108
+ console.log(` -> ${nPurged} versions purged from log.`);
109
+ else
110
+ console.log(` -> No versions purged from log.`);
104
111
  }
105
112
  }
106
113
  }
@@ -111,23 +118,28 @@ class VersionDb {
111
118
  }
112
119
 
113
120
  async load() {
114
- const versionMap = this.versionMap = new Map();
121
+ const map = this.map = new Map();
115
122
  if (await fs.pathExists(this.baseDir)) {
116
123
  const dirs = await fs.readdir(this.baseDir);
117
124
  for (const dir of dirs) {
118
125
  const version = this.myt.parseVersionDir(dir);
119
126
  if (!version) continue;
120
- versionMap.set(version.number, dir);
127
+ let subdirs = map.get(version.number);
128
+ if (!subdirs) map.set(version.number, subdirs = []);
129
+ subdirs.push(dir);
121
130
  }
122
131
  }
123
- return versionMap;
132
+ return map;
124
133
  }
125
134
 
126
135
  async hasScript(script) {
127
- const dir = this.versionMap.get(script.number);
128
- if (!dir) return false;
129
- const scriptPath = path.join(this.baseDir, dir, script.file);
130
- return await fs.pathExists(scriptPath);
136
+ const dirs = this.map.get(script.number);
137
+ if (dirs)
138
+ for (const dir of dirs) {
139
+ const scriptPath = path.join(this.baseDir, dir, script.file);
140
+ if (await fs.pathExists(scriptPath)) return true;
141
+ }
142
+ return false;
131
143
  }
132
144
  }
133
145
 
package/myt-push.js CHANGED
@@ -138,6 +138,7 @@ class Push extends Command {
138
138
 
139
139
  console.log('Applying versions.');
140
140
 
141
+ let nVersions = 0;
141
142
  let nChanges = 0;
142
143
  let silent = true;
143
144
  const versionsDir = opts.versionsDir;
@@ -191,7 +192,6 @@ class Push extends Command {
191
192
 
192
193
  const action = apply ? 'apply' : 'ignore';
193
194
  logVersion(`[${version.number}]`.cyan, version.name, action);
194
-
195
195
  if (!apply) continue;
196
196
 
197
197
  for (const script of version.scripts) {
@@ -243,9 +243,15 @@ class Push extends Command {
243
243
  }
244
244
 
245
245
  await this.updateVersion('number', version.number);
246
+ nVersions++;
246
247
  }
247
248
  }
248
249
 
250
+ if (nVersions) {
251
+ console.log(` -> ${nVersions} versions with ${nChanges} changes applied.`);
252
+ } else
253
+ console.log(` -> No versions applied.`);
254
+
249
255
  // Apply routines
250
256
 
251
257
  console.log('Applying changed routines.');
@@ -381,8 +387,8 @@ class Push extends Command {
381
387
 
382
388
  await finalize();
383
389
 
384
- if (nRoutines > 0) {
385
- console.log(` -> ${nRoutines} routines have changed.`);
390
+ if (nRoutines) {
391
+ console.log(` -> ${nRoutines} routines changed.`);
386
392
  } else
387
393
  console.log(` -> No routines changed.`);
388
394
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdnatura/myt",
3
- "version": "1.5.26",
3
+ "version": "1.5.27",
4
4
  "author": "Verdnatura Levante SL",
5
5
  "description": "MySQL version control",
6
6
  "license": "GPL-3.0",