mpx-db 1.1.0 → 1.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mpx-db",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Database management CLI - Connect, query, migrate, and manage databases from the terminal",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/cli.js CHANGED
@@ -153,6 +153,78 @@ program
153
153
  .option('-o, --output <file>', 'Output file path')
154
154
  .action((target, table, options) => exportData(target, table, { ...globalOptions, ...options }));
155
155
 
156
+ // Update subcommand
157
+ program
158
+ .command('update')
159
+ .description('Check for updates and optionally install the latest version')
160
+ .option('--check', 'Only check for updates (do not install)')
161
+ .action(async (options) => {
162
+ const { checkForUpdate, performUpdate } = await import('./update.js');
163
+ const jsonMode = globalOptions.json;
164
+
165
+ try {
166
+ const info = checkForUpdate();
167
+
168
+ if (jsonMode) {
169
+ const output = {
170
+ current: info.current,
171
+ latest: info.latest,
172
+ updateAvailable: info.updateAvailable,
173
+ isGlobal: info.isGlobal
174
+ };
175
+
176
+ if (!options.check && info.updateAvailable) {
177
+ try {
178
+ const result = performUpdate(info.isGlobal);
179
+ output.updated = true;
180
+ output.newVersion = result.version;
181
+ } catch (err) {
182
+ output.updated = false;
183
+ output.error = err.message;
184
+ }
185
+ }
186
+
187
+ console.log(JSON.stringify(output, null, 2));
188
+ process.exit(0);
189
+ return;
190
+ }
191
+
192
+ // Human-readable output
193
+ if (!info.updateAvailable) {
194
+ console.log('');
195
+ console.log(chalk.green.bold(`✓ mpx-db v${info.current} is up to date`));
196
+ console.log('');
197
+ process.exit(0);
198
+ return;
199
+ }
200
+
201
+ console.log('');
202
+ console.log(chalk.yellow.bold(`⬆ Update available: v${info.current} → v${info.latest}`));
203
+
204
+ if (options.check) {
205
+ console.log(chalk.gray(`Run ${chalk.cyan('mpx-db update')} to install`));
206
+ console.log('');
207
+ process.exit(0);
208
+ return;
209
+ }
210
+
211
+ console.log(chalk.gray(`Installing v${info.latest}${info.isGlobal ? ' (global)' : ''}...`));
212
+
213
+ const result = performUpdate(info.isGlobal);
214
+ console.log(chalk.green.bold(`✓ Updated to v${result.version}`));
215
+ console.log('');
216
+ process.exit(0);
217
+ } catch (err) {
218
+ if (jsonMode) {
219
+ console.log(JSON.stringify({ error: err.message, code: 'ERR_UPDATE' }, null, 2));
220
+ } else {
221
+ console.error(chalk.red.bold('\n❌ Update check failed:'), err.message);
222
+ console.error('');
223
+ }
224
+ process.exit(1);
225
+ }
226
+ });
227
+
156
228
  // MCP subcommand
157
229
  program
158
230
  .command('mcp')
package/src/schema.js CHANGED
@@ -560,6 +560,19 @@ export function getSchema() {
560
560
  examples: [
561
561
  { command: 'mpx-db mcp', description: 'Start MCP stdio server' }
562
562
  ]
563
+ },
564
+ update: {
565
+ description: 'Check for updates and optionally install the latest version',
566
+ usage: 'mpx-db update [--check] [--json]',
567
+ flags: {
568
+ '--check': { description: 'Only check for updates (do not install)', default: false },
569
+ '--json': { description: 'Machine-readable JSON output', default: false }
570
+ },
571
+ examples: [
572
+ { command: 'mpx-db update', description: 'Check and install updates' },
573
+ { command: 'mpx-db update --check', description: 'Just check for updates' },
574
+ { command: 'mpx-db update --check --json', description: 'Check for updates (JSON output)' }
575
+ ]
563
576
  }
564
577
  },
565
578
  mcpConfig: {
package/src/update.js ADDED
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Update Command
3
+ *
4
+ * Checks npm for the latest version of mpx-db and offers to update.
5
+ */
6
+
7
+ import { execSync } from 'child_process';
8
+ import { readFileSync } from 'fs';
9
+ import { fileURLToPath } from 'url';
10
+ import { dirname, join } from 'path';
11
+
12
+ const __filename = fileURLToPath(import.meta.url);
13
+ const __dirname = dirname(__filename);
14
+ const pkg = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf8'));
15
+
16
+ /**
17
+ * Check npm registry for latest version
18
+ * @returns {object} { current, latest, updateAvailable, isGlobal }
19
+ */
20
+ export function checkForUpdate() {
21
+ const current = pkg.version;
22
+
23
+ let latest;
24
+ try {
25
+ latest = execSync('npm view mpx-db version', { encoding: 'utf8', timeout: 10000 }).trim();
26
+ } catch (err) {
27
+ throw new Error('Failed to check npm registry: ' + (err.message || 'unknown error'));
28
+ }
29
+
30
+ const updateAvailable = latest !== current && compareVersions(latest, current) > 0;
31
+
32
+ // Detect if installed globally
33
+ let isGlobal = false;
34
+ try {
35
+ const globalDir = execSync('npm root -g', { encoding: 'utf8', timeout: 5000 }).trim();
36
+ isGlobal = __dirname.startsWith(globalDir) || process.argv[1]?.includes('node_modules/.bin');
37
+ } catch {
38
+ // Can't determine, assume local
39
+ }
40
+
41
+ return { current, latest, updateAvailable, isGlobal };
42
+ }
43
+
44
+ /**
45
+ * Perform the update
46
+ * @param {boolean} isGlobal - Install globally
47
+ * @returns {object} { success, version }
48
+ */
49
+ export function performUpdate(isGlobal) {
50
+ const cmd = isGlobal ? 'npm install -g mpx-db@latest' : 'npm install mpx-db@latest';
51
+ try {
52
+ execSync(cmd, { encoding: 'utf8', timeout: 60000, stdio: 'pipe' });
53
+ // Verify
54
+ const newVersion = execSync('npm view mpx-db version', { encoding: 'utf8', timeout: 10000 }).trim();
55
+ return { success: true, version: newVersion };
56
+ } catch (err) {
57
+ throw new Error('Update failed: ' + (err.message || 'unknown error'));
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Compare semver strings. Returns >0 if a > b, <0 if a < b, 0 if equal.
63
+ */
64
+ export function compareVersions(a, b) {
65
+ const pa = a.split('.').map(Number);
66
+ const pb = b.split('.').map(Number);
67
+ for (let i = 0; i < 3; i++) {
68
+ if ((pa[i] || 0) > (pb[i] || 0)) return 1;
69
+ if ((pa[i] || 0) < (pb[i] || 0)) return -1;
70
+ }
71
+ return 0;
72
+ }