monomind 1.18.9 → 1.18.10
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 +1 -1
- package/packages/@monomind/cli/dist/src/commands/hooks-coverage-commands.d.ts +1 -2
- package/packages/@monomind/cli/dist/src/commands/hooks-coverage-commands.js +1 -2
- package/packages/@monomind/cli/dist/src/commands/hooks-coverage-gaps.d.ts +1 -2
- package/packages/@monomind/cli/dist/src/commands/hooks-coverage-gaps.js +2 -117
- package/packages/@monomind/cli/dist/src/commands/hooks.js +1 -2
- package/packages/@monomind/cli/dist/src/commands/index.d.ts +0 -1
- package/packages/@monomind/cli/dist/src/commands/index.js +0 -1
- package/packages/@monomind/cli/dist/src/init/executor.d.ts +3 -0
- package/packages/@monomind/cli/dist/src/init/executor.js +20 -111
- package/packages/@monomind/cli/dist/src/mcp-client.js +0 -2
- package/packages/@monomind/cli/dist/src/mcp-tools/index.d.ts +0 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/index.js +0 -1
- package/packages/@monomind/cli/dist/src/mcp-tools/quality/coverage-analysis/track-trends.d.ts +4 -4
- package/packages/@monomind/cli/dist/src/mcp-tools/quality/test-generation/suggest-tests.d.ts +4 -4
- package/packages/@monomind/cli/package.json +1 -1
- package/packages/@monomind/cli/dist/src/benchmarks/benchmark-runner.d.ts +0 -134
- package/packages/@monomind/cli/dist/src/benchmarks/benchmark-runner.js +0 -340
- package/packages/@monomind/cli/dist/src/benchmarks/metric-evaluators.d.ts +0 -36
- package/packages/@monomind/cli/dist/src/benchmarks/metric-evaluators.js +0 -125
- package/packages/@monomind/cli/dist/src/commands/benchmark.d.ts +0 -10
- package/packages/@monomind/cli/dist/src/commands/benchmark.js +0 -586
- package/packages/@monomind/cli/dist/src/commands/migrate.d.ts +0 -8
- package/packages/@monomind/cli/dist/src/commands/migrate.js +0 -789
- package/packages/@monomind/cli/dist/src/commands/monovector/backup.d.ts +0 -11
- package/packages/@monomind/cli/dist/src/commands/monovector/backup.js +0 -752
- package/packages/@monomind/cli/dist/src/commands/monovector/benchmark.d.ts +0 -11
- package/packages/@monomind/cli/dist/src/commands/monovector/benchmark.js +0 -502
- package/packages/@monomind/cli/dist/src/commands/monovector/import.d.ts +0 -18
- package/packages/@monomind/cli/dist/src/commands/monovector/import.js +0 -374
- package/packages/@monomind/cli/dist/src/commands/monovector/index.d.ts +0 -29
- package/packages/@monomind/cli/dist/src/commands/monovector/index.js +0 -129
- package/packages/@monomind/cli/dist/src/commands/monovector/init.d.ts +0 -11
- package/packages/@monomind/cli/dist/src/commands/monovector/init.js +0 -481
- package/packages/@monomind/cli/dist/src/commands/monovector/migrate.d.ts +0 -11
- package/packages/@monomind/cli/dist/src/commands/monovector/migrate.js +0 -500
- package/packages/@monomind/cli/dist/src/commands/monovector/optimize.d.ts +0 -11
- package/packages/@monomind/cli/dist/src/commands/monovector/optimize.js +0 -515
- package/packages/@monomind/cli/dist/src/commands/monovector/setup.d.ts +0 -18
- package/packages/@monomind/cli/dist/src/commands/monovector/setup.js +0 -775
- package/packages/@monomind/cli/dist/src/commands/monovector/status.d.ts +0 -11
- package/packages/@monomind/cli/dist/src/commands/monovector/status.js +0 -491
- package/packages/@monomind/cli/dist/src/commands/progress.d.ts +0 -11
- package/packages/@monomind/cli/dist/src/commands/progress.js +0 -261
- package/packages/@monomind/cli/dist/src/mcp-tools/progress-tools.d.ts +0 -14
- package/packages/@monomind/cli/dist/src/mcp-tools/progress-tools.js +0 -353
|
@@ -1,500 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI MonoVector Migrate Command
|
|
3
|
-
* Database migration management for MonoVector
|
|
4
|
-
*/
|
|
5
|
-
import { output } from '../../output.js';
|
|
6
|
-
import { confirm } from '../../prompt.js';
|
|
7
|
-
/**
|
|
8
|
-
* Available migrations
|
|
9
|
-
*/
|
|
10
|
-
const MIGRATIONS = [
|
|
11
|
-
{
|
|
12
|
-
version: '1.0.0',
|
|
13
|
-
name: 'Initial MonoVector setup',
|
|
14
|
-
up: '-- Initial setup handled by init command',
|
|
15
|
-
down: '-- Drop all tables in schema',
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
version: '1.1.0',
|
|
19
|
-
name: 'Add full-text search',
|
|
20
|
-
up: `
|
|
21
|
-
CREATE INDEX IF NOT EXISTS idx_embeddings_content_fts
|
|
22
|
-
ON {{schema}}.embeddings
|
|
23
|
-
USING gin (to_tsvector('english', COALESCE(content, '')));
|
|
24
|
-
|
|
25
|
-
ALTER TABLE {{schema}}.embeddings
|
|
26
|
-
ADD COLUMN IF NOT EXISTS search_vector tsvector
|
|
27
|
-
GENERATED ALWAYS AS (to_tsvector('english', COALESCE(content, ''))) STORED;
|
|
28
|
-
`,
|
|
29
|
-
down: `
|
|
30
|
-
DROP INDEX IF EXISTS {{schema}}.idx_embeddings_content_fts;
|
|
31
|
-
ALTER TABLE {{schema}}.embeddings DROP COLUMN IF EXISTS search_vector;
|
|
32
|
-
`,
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
version: '1.2.0',
|
|
36
|
-
name: 'Add embedding statistics',
|
|
37
|
-
up: `
|
|
38
|
-
CREATE TABLE IF NOT EXISTS {{schema}}.embedding_stats (
|
|
39
|
-
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
40
|
-
namespace VARCHAR(128) NOT NULL,
|
|
41
|
-
total_vectors INTEGER DEFAULT 0,
|
|
42
|
-
avg_magnitude FLOAT,
|
|
43
|
-
dimension_stats JSONB,
|
|
44
|
-
computed_at TIMESTAMPTZ DEFAULT NOW()
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
CREATE INDEX IF NOT EXISTS idx_embedding_stats_namespace
|
|
48
|
-
ON {{schema}}.embedding_stats (namespace);
|
|
49
|
-
`,
|
|
50
|
-
down: `
|
|
51
|
-
DROP TABLE IF EXISTS {{schema}}.embedding_stats;
|
|
52
|
-
`,
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
version: '1.3.0',
|
|
56
|
-
name: 'Add query cache',
|
|
57
|
-
up: `
|
|
58
|
-
CREATE TABLE IF NOT EXISTS {{schema}}.query_cache (
|
|
59
|
-
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
60
|
-
query_hash VARCHAR(64) NOT NULL UNIQUE,
|
|
61
|
-
query_embedding {{vector_type}}(1536),
|
|
62
|
-
result_ids UUID[],
|
|
63
|
-
result_scores FLOAT[],
|
|
64
|
-
hit_count INTEGER DEFAULT 1,
|
|
65
|
-
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
66
|
-
last_accessed TIMESTAMPTZ DEFAULT NOW()
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
CREATE INDEX IF NOT EXISTS idx_query_cache_hash
|
|
70
|
-
ON {{schema}}.query_cache (query_hash);
|
|
71
|
-
|
|
72
|
-
CREATE INDEX IF NOT EXISTS idx_query_cache_last_accessed
|
|
73
|
-
ON {{schema}}.query_cache (last_accessed);
|
|
74
|
-
`,
|
|
75
|
-
down: `
|
|
76
|
-
DROP TABLE IF EXISTS {{schema}}.query_cache;
|
|
77
|
-
`,
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
version: '1.4.0',
|
|
81
|
-
name: 'Add batch operations support',
|
|
82
|
-
up: `
|
|
83
|
-
CREATE TABLE IF NOT EXISTS {{schema}}.batch_jobs (
|
|
84
|
-
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
85
|
-
job_type VARCHAR(64) NOT NULL,
|
|
86
|
-
status VARCHAR(32) DEFAULT 'pending',
|
|
87
|
-
total_items INTEGER DEFAULT 0,
|
|
88
|
-
processed_items INTEGER DEFAULT 0,
|
|
89
|
-
error_count INTEGER DEFAULT 0,
|
|
90
|
-
metadata JSONB DEFAULT '{}',
|
|
91
|
-
started_at TIMESTAMPTZ,
|
|
92
|
-
completed_at TIMESTAMPTZ,
|
|
93
|
-
created_at TIMESTAMPTZ DEFAULT NOW()
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
CREATE INDEX IF NOT EXISTS idx_batch_jobs_status
|
|
97
|
-
ON {{schema}}.batch_jobs (status);
|
|
98
|
-
`,
|
|
99
|
-
down: `
|
|
100
|
-
DROP TABLE IF EXISTS {{schema}}.batch_jobs;
|
|
101
|
-
`,
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
version: '1.5.0',
|
|
105
|
-
name: 'Add neural pattern learning',
|
|
106
|
-
up: `
|
|
107
|
-
CREATE TABLE IF NOT EXISTS {{schema}}.neural_patterns (
|
|
108
|
-
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
109
|
-
pattern_type VARCHAR(64) NOT NULL,
|
|
110
|
-
input_embedding {{vector_type}}(1536),
|
|
111
|
-
output_embedding {{vector_type}}(1536),
|
|
112
|
-
weight_matrix JSONB,
|
|
113
|
-
activation VARCHAR(32) DEFAULT 'relu',
|
|
114
|
-
accuracy FLOAT,
|
|
115
|
-
training_steps INTEGER DEFAULT 0,
|
|
116
|
-
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
117
|
-
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
CREATE INDEX IF NOT EXISTS idx_neural_patterns_type
|
|
121
|
-
ON {{schema}}.neural_patterns (pattern_type);
|
|
122
|
-
|
|
123
|
-
CREATE INDEX IF NOT EXISTS idx_neural_patterns_input_hnsw
|
|
124
|
-
ON {{schema}}.neural_patterns
|
|
125
|
-
USING hnsw (input_embedding {{cosine_ops}})
|
|
126
|
-
WITH (m = 16, ef_construction = 64);
|
|
127
|
-
`,
|
|
128
|
-
down: `
|
|
129
|
-
DROP TABLE IF EXISTS {{schema}}.neural_patterns;
|
|
130
|
-
`,
|
|
131
|
-
},
|
|
132
|
-
];
|
|
133
|
-
const IDENTIFIER_RE = /^[a-zA-Z_][a-zA-Z0-9_]{0,63}$/;
|
|
134
|
-
/**
|
|
135
|
-
* Get PostgreSQL connection config from context
|
|
136
|
-
*/
|
|
137
|
-
function getConnectionConfig(ctx) {
|
|
138
|
-
const rawSchema = ctx.flags.schema || 'monomind';
|
|
139
|
-
const schema = IDENTIFIER_RE.test(rawSchema) ? rawSchema : 'monomind';
|
|
140
|
-
return {
|
|
141
|
-
host: ctx.flags.host || process.env.PGHOST || 'localhost',
|
|
142
|
-
port: parseInt(ctx.flags.port || process.env.PGPORT || '5432', 10),
|
|
143
|
-
database: ctx.flags.database || process.env.PGDATABASE || '',
|
|
144
|
-
user: ctx.flags.user || process.env.PGUSER || 'postgres',
|
|
145
|
-
password: ctx.flags.password || process.env.PGPASSWORD || '',
|
|
146
|
-
ssl: ctx.flags.ssl || process.env.PGSSLMODE === 'require',
|
|
147
|
-
schema,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Calculate simple checksum for migration SQL
|
|
152
|
-
*/
|
|
153
|
-
function calculateChecksum(sql) {
|
|
154
|
-
let hash = 0;
|
|
155
|
-
for (let i = 0; i < sql.length; i++) {
|
|
156
|
-
const char = sql.charCodeAt(i);
|
|
157
|
-
hash = ((hash << 5) - hash) + char;
|
|
158
|
-
hash = hash & hash;
|
|
159
|
-
}
|
|
160
|
-
return Math.abs(hash).toString(16).padStart(8, '0');
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* MonoVector migrate command
|
|
164
|
-
*/
|
|
165
|
-
export const migrateCommand = {
|
|
166
|
-
name: 'migrate',
|
|
167
|
-
description: 'Run database migrations',
|
|
168
|
-
options: [
|
|
169
|
-
{
|
|
170
|
-
name: 'up',
|
|
171
|
-
description: 'Run pending migrations (default)',
|
|
172
|
-
type: 'boolean',
|
|
173
|
-
default: true,
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
name: 'down',
|
|
177
|
-
description: 'Rollback last migration',
|
|
178
|
-
type: 'boolean',
|
|
179
|
-
default: false,
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
name: 'to',
|
|
183
|
-
description: 'Migrate to specific version',
|
|
184
|
-
type: 'string',
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
name: 'dry-run',
|
|
188
|
-
description: 'Show SQL without executing',
|
|
189
|
-
type: 'boolean',
|
|
190
|
-
default: false,
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
name: 'force',
|
|
194
|
-
description: 'Force migration even if dirty',
|
|
195
|
-
type: 'boolean',
|
|
196
|
-
default: false,
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
name: 'host',
|
|
200
|
-
short: 'h',
|
|
201
|
-
description: 'PostgreSQL host',
|
|
202
|
-
type: 'string',
|
|
203
|
-
default: 'localhost',
|
|
204
|
-
},
|
|
205
|
-
{
|
|
206
|
-
name: 'port',
|
|
207
|
-
short: 'p',
|
|
208
|
-
description: 'PostgreSQL port',
|
|
209
|
-
type: 'number',
|
|
210
|
-
default: 5432,
|
|
211
|
-
},
|
|
212
|
-
{
|
|
213
|
-
name: 'database',
|
|
214
|
-
short: 'd',
|
|
215
|
-
description: 'Database name',
|
|
216
|
-
type: 'string',
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
name: 'user',
|
|
220
|
-
short: 'u',
|
|
221
|
-
description: 'Database user',
|
|
222
|
-
type: 'string',
|
|
223
|
-
},
|
|
224
|
-
{
|
|
225
|
-
name: 'password',
|
|
226
|
-
description: 'Database password',
|
|
227
|
-
type: 'string',
|
|
228
|
-
},
|
|
229
|
-
{
|
|
230
|
-
name: 'ssl',
|
|
231
|
-
description: 'Enable SSL',
|
|
232
|
-
type: 'boolean',
|
|
233
|
-
default: false,
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
name: 'schema',
|
|
237
|
-
short: 's',
|
|
238
|
-
description: 'Schema name',
|
|
239
|
-
type: 'string',
|
|
240
|
-
default: 'monomind',
|
|
241
|
-
},
|
|
242
|
-
],
|
|
243
|
-
examples: [
|
|
244
|
-
{ command: 'monomind monovector migrate --up', description: 'Run pending migrations' },
|
|
245
|
-
{ command: 'monomind monovector migrate --down', description: 'Rollback last migration' },
|
|
246
|
-
{ command: 'monomind monovector migrate --to 1.2.0', description: 'Migrate to version 1.2.0' },
|
|
247
|
-
{ command: 'monomind monovector migrate --dry-run', description: 'Preview migration SQL' },
|
|
248
|
-
],
|
|
249
|
-
action: async (ctx) => {
|
|
250
|
-
const config = getConnectionConfig(ctx);
|
|
251
|
-
const dryRun = ctx.flags['dry-run'];
|
|
252
|
-
const force = ctx.flags.force;
|
|
253
|
-
const targetVersion = ctx.flags.to;
|
|
254
|
-
const rollback = ctx.flags.down;
|
|
255
|
-
output.writeln();
|
|
256
|
-
output.writeln(output.bold('MonoVector Migration'));
|
|
257
|
-
output.writeln(output.dim('='.repeat(60)));
|
|
258
|
-
output.writeln();
|
|
259
|
-
if (!config.database) {
|
|
260
|
-
output.printError('Database name is required. Use --database or -d flag, or set PGDATABASE env.');
|
|
261
|
-
return { success: false, exitCode: 1 };
|
|
262
|
-
}
|
|
263
|
-
if (dryRun) {
|
|
264
|
-
output.printInfo('Dry run mode: SQL will be shown but not executed');
|
|
265
|
-
output.writeln();
|
|
266
|
-
}
|
|
267
|
-
const spinner = output.createSpinner({ text: 'Connecting to PostgreSQL...', spinner: 'dots' });
|
|
268
|
-
spinner.start();
|
|
269
|
-
try {
|
|
270
|
-
// Import pg
|
|
271
|
-
let pg = null;
|
|
272
|
-
try {
|
|
273
|
-
pg = await import('pg');
|
|
274
|
-
}
|
|
275
|
-
catch {
|
|
276
|
-
spinner.fail('PostgreSQL driver not found');
|
|
277
|
-
output.printError('Install pg package: npm install pg');
|
|
278
|
-
return { success: false, exitCode: 1 };
|
|
279
|
-
}
|
|
280
|
-
const client = new pg.Client({
|
|
281
|
-
host: config.host,
|
|
282
|
-
port: config.port,
|
|
283
|
-
database: config.database,
|
|
284
|
-
user: config.user,
|
|
285
|
-
password: config.password,
|
|
286
|
-
ssl: config.ssl ? { rejectUnauthorized: false } : false,
|
|
287
|
-
});
|
|
288
|
-
await client.connect();
|
|
289
|
-
spinner.succeed('Connected to PostgreSQL');
|
|
290
|
-
// Detect vector extension type: prefer monovector, fall back to pgvector
|
|
291
|
-
let vectorTypeName = 'vector';
|
|
292
|
-
let cosineOps = 'vector_cosine_ops';
|
|
293
|
-
const monovectorCheck = await client.query(`
|
|
294
|
-
SELECT extname FROM pg_extension WHERE extname = 'monovector'
|
|
295
|
-
`);
|
|
296
|
-
if (monovectorCheck.rows.length > 0) {
|
|
297
|
-
vectorTypeName = 'monovector';
|
|
298
|
-
cosineOps = 'monovector_cosine_ops';
|
|
299
|
-
}
|
|
300
|
-
// Check if schema and migrations table exist
|
|
301
|
-
spinner.setText('Checking migration status...');
|
|
302
|
-
spinner.start();
|
|
303
|
-
const schemaExists = await client.query(`
|
|
304
|
-
SELECT schema_name FROM information_schema.schemata WHERE schema_name = $1
|
|
305
|
-
`, [config.schema]);
|
|
306
|
-
if (schemaExists.rows.length === 0) {
|
|
307
|
-
spinner.fail(`Schema "${config.schema}" not found`);
|
|
308
|
-
output.printError('Run `monomind monovector init` first');
|
|
309
|
-
await client.end();
|
|
310
|
-
return { success: false, exitCode: 1 };
|
|
311
|
-
}
|
|
312
|
-
// Get applied migrations
|
|
313
|
-
const appliedResult = await client.query(`
|
|
314
|
-
SELECT version, name, applied_at, checksum
|
|
315
|
-
FROM ${config.schema}.migrations
|
|
316
|
-
ORDER BY version ASC
|
|
317
|
-
`);
|
|
318
|
-
const appliedVersions = new Set(appliedResult.rows.map(r => r.version));
|
|
319
|
-
spinner.succeed(`Found ${appliedVersions.size} applied migrations`);
|
|
320
|
-
// Determine migrations to run
|
|
321
|
-
let migrationsToRun = [];
|
|
322
|
-
let direction = 'up';
|
|
323
|
-
if (rollback) {
|
|
324
|
-
direction = 'down';
|
|
325
|
-
// Get the last applied migration
|
|
326
|
-
const lastApplied = appliedResult.rows[appliedResult.rows.length - 1];
|
|
327
|
-
if (!lastApplied) {
|
|
328
|
-
output.printWarning('No migrations to rollback');
|
|
329
|
-
await client.end();
|
|
330
|
-
return { success: true };
|
|
331
|
-
}
|
|
332
|
-
const migration = MIGRATIONS.find(m => m.version === lastApplied.version);
|
|
333
|
-
if (migration) {
|
|
334
|
-
migrationsToRun = [migration];
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
else if (targetVersion) {
|
|
338
|
-
// Migrate to specific version
|
|
339
|
-
const targetIdx = MIGRATIONS.findIndex(m => m.version === targetVersion);
|
|
340
|
-
if (targetIdx === -1) {
|
|
341
|
-
output.printError(`Version ${targetVersion} not found`);
|
|
342
|
-
await client.end();
|
|
343
|
-
return { success: false, exitCode: 1 };
|
|
344
|
-
}
|
|
345
|
-
const currentVersions = Array.from(appliedVersions);
|
|
346
|
-
const currentIdx = currentVersions.length > 0
|
|
347
|
-
? MIGRATIONS.findIndex(m => m.version === currentVersions[currentVersions.length - 1])
|
|
348
|
-
: -1;
|
|
349
|
-
if (targetIdx > currentIdx) {
|
|
350
|
-
// Migrate up
|
|
351
|
-
migrationsToRun = MIGRATIONS.slice(currentIdx + 1, targetIdx + 1)
|
|
352
|
-
.filter(m => !appliedVersions.has(m.version));
|
|
353
|
-
}
|
|
354
|
-
else if (targetIdx < currentIdx) {
|
|
355
|
-
// Migrate down
|
|
356
|
-
direction = 'down';
|
|
357
|
-
migrationsToRun = MIGRATIONS.slice(targetIdx + 1, currentIdx + 1)
|
|
358
|
-
.filter(m => appliedVersions.has(m.version))
|
|
359
|
-
.reverse();
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
else {
|
|
363
|
-
// Run all pending migrations
|
|
364
|
-
migrationsToRun = MIGRATIONS.filter(m => !appliedVersions.has(m.version));
|
|
365
|
-
}
|
|
366
|
-
if (migrationsToRun.length === 0) {
|
|
367
|
-
output.printSuccess('Database is up to date');
|
|
368
|
-
// Show current migration status
|
|
369
|
-
output.writeln();
|
|
370
|
-
output.writeln(output.highlight('Applied Migrations:'));
|
|
371
|
-
output.printTable({
|
|
372
|
-
columns: [
|
|
373
|
-
{ key: 'version', header: 'Version', width: 12 },
|
|
374
|
-
{ key: 'name', header: 'Name', width: 35 },
|
|
375
|
-
{ key: 'applied', header: 'Applied At', width: 22 },
|
|
376
|
-
],
|
|
377
|
-
data: appliedResult.rows.map(r => ({
|
|
378
|
-
version: r.version,
|
|
379
|
-
name: r.name,
|
|
380
|
-
applied: new Date(r.applied_at).toISOString().replace('T', ' ').substring(0, 19),
|
|
381
|
-
})),
|
|
382
|
-
});
|
|
383
|
-
await client.end();
|
|
384
|
-
return { success: true };
|
|
385
|
-
}
|
|
386
|
-
// Show migrations to run
|
|
387
|
-
output.writeln();
|
|
388
|
-
output.writeln(output.highlight(`Migrations to ${direction === 'up' ? 'apply' : 'rollback'}:`));
|
|
389
|
-
output.printTable({
|
|
390
|
-
columns: [
|
|
391
|
-
{ key: 'version', header: 'Version', width: 12 },
|
|
392
|
-
{ key: 'name', header: 'Name', width: 40 },
|
|
393
|
-
{ key: 'direction', header: 'Direction', width: 10 },
|
|
394
|
-
],
|
|
395
|
-
data: migrationsToRun.map(m => ({
|
|
396
|
-
version: m.version,
|
|
397
|
-
name: m.name,
|
|
398
|
-
direction: direction === 'up' ? output.success('UP') : output.warning('DOWN'),
|
|
399
|
-
})),
|
|
400
|
-
});
|
|
401
|
-
output.writeln();
|
|
402
|
-
// Dry run: show SQL
|
|
403
|
-
if (dryRun) {
|
|
404
|
-
for (const migration of migrationsToRun) {
|
|
405
|
-
const sql = direction === 'up' ? migration.up : migration.down;
|
|
406
|
-
const resolvedSql = sql
|
|
407
|
-
.replace(/\{\{schema\}\}/g, config.schema)
|
|
408
|
-
.replace(/\{\{vector_type\}\}/g, vectorTypeName)
|
|
409
|
-
.replace(/\{\{cosine_ops\}\}/g, cosineOps);
|
|
410
|
-
output.writeln(output.bold(`-- Migration ${migration.version}: ${migration.name}`));
|
|
411
|
-
output.writeln(output.dim('-- Direction: ' + direction.toUpperCase()));
|
|
412
|
-
output.writeln();
|
|
413
|
-
output.writeln(resolvedSql);
|
|
414
|
-
output.writeln();
|
|
415
|
-
}
|
|
416
|
-
await client.end();
|
|
417
|
-
return { success: true, data: { dryRun: true, migrations: migrationsToRun.map(m => m.version) } };
|
|
418
|
-
}
|
|
419
|
-
// Confirm before running
|
|
420
|
-
if (ctx.interactive && !force) {
|
|
421
|
-
const confirmRun = await confirm({
|
|
422
|
-
message: `Run ${migrationsToRun.length} migration(s)?`,
|
|
423
|
-
default: true,
|
|
424
|
-
});
|
|
425
|
-
if (!confirmRun) {
|
|
426
|
-
output.printInfo('Migration cancelled');
|
|
427
|
-
await client.end();
|
|
428
|
-
return { success: false, exitCode: 0 };
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
// Run migrations
|
|
432
|
-
const results = [];
|
|
433
|
-
for (const migration of migrationsToRun) {
|
|
434
|
-
spinner.setText(`Running migration ${migration.version}: ${migration.name}...`);
|
|
435
|
-
spinner.start();
|
|
436
|
-
try {
|
|
437
|
-
const sql = direction === 'up' ? migration.up : migration.down;
|
|
438
|
-
const resolvedSql = sql
|
|
439
|
-
.replace(/\{\{schema\}\}/g, config.schema)
|
|
440
|
-
.replace(/\{\{vector_type\}\}/g, vectorTypeName)
|
|
441
|
-
.replace(/\{\{cosine_ops\}\}/g, cosineOps);
|
|
442
|
-
await client.query('BEGIN');
|
|
443
|
-
// Execute migration SQL
|
|
444
|
-
await client.query(resolvedSql);
|
|
445
|
-
// Update migrations table
|
|
446
|
-
if (direction === 'up') {
|
|
447
|
-
const checksum = calculateChecksum(resolvedSql);
|
|
448
|
-
await client.query(`
|
|
449
|
-
INSERT INTO ${config.schema}.migrations (version, name, checksum)
|
|
450
|
-
VALUES ($1, $2, $3)
|
|
451
|
-
ON CONFLICT (version) DO UPDATE SET applied_at = NOW()
|
|
452
|
-
`, [migration.version, migration.name, checksum]);
|
|
453
|
-
}
|
|
454
|
-
else {
|
|
455
|
-
await client.query(`
|
|
456
|
-
DELETE FROM ${config.schema}.migrations WHERE version = $1
|
|
457
|
-
`, [migration.version]);
|
|
458
|
-
}
|
|
459
|
-
await client.query('COMMIT');
|
|
460
|
-
spinner.succeed(`Migration ${migration.version} ${direction === 'up' ? 'applied' : 'rolled back'}`);
|
|
461
|
-
results.push({ version: migration.version, success: true });
|
|
462
|
-
}
|
|
463
|
-
catch (error) {
|
|
464
|
-
await client.query('ROLLBACK');
|
|
465
|
-
spinner.fail(`Migration ${migration.version} failed`);
|
|
466
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
467
|
-
output.printError(errorMessage);
|
|
468
|
-
results.push({ version: migration.version, success: false, error: errorMessage });
|
|
469
|
-
if (!force) {
|
|
470
|
-
output.printWarning('Stopping migration due to error. Use --force to continue.');
|
|
471
|
-
break;
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
await client.end();
|
|
476
|
-
// Summary
|
|
477
|
-
output.writeln();
|
|
478
|
-
const successful = results.filter(r => r.success).length;
|
|
479
|
-
const failed = results.filter(r => !r.success).length;
|
|
480
|
-
if (failed === 0) {
|
|
481
|
-
output.printSuccess(`All ${successful} migration(s) completed successfully`);
|
|
482
|
-
}
|
|
483
|
-
else {
|
|
484
|
-
output.printWarning(`${successful} succeeded, ${failed} failed`);
|
|
485
|
-
}
|
|
486
|
-
return {
|
|
487
|
-
success: failed === 0,
|
|
488
|
-
data: { results },
|
|
489
|
-
exitCode: failed > 0 ? 1 : 0,
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
catch (error) {
|
|
493
|
-
spinner.fail('Migration failed');
|
|
494
|
-
output.printError(error instanceof Error ? error.message : String(error));
|
|
495
|
-
return { success: false, exitCode: 1 };
|
|
496
|
-
}
|
|
497
|
-
},
|
|
498
|
-
};
|
|
499
|
-
export default migrateCommand;
|
|
500
|
-
//# sourceMappingURL=migrate.js.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI MonoVector Optimize Command
|
|
3
|
-
* Optimization analysis and recommendations
|
|
4
|
-
*/
|
|
5
|
-
import type { Command } from '../../types.js';
|
|
6
|
-
/**
|
|
7
|
-
* MonoVector optimize command
|
|
8
|
-
*/
|
|
9
|
-
export declare const optimizeCommand: Command;
|
|
10
|
-
export default optimizeCommand;
|
|
11
|
-
//# sourceMappingURL=optimize.d.ts.map
|