morpheus4j
Version:
Morpheus is a migration tool for Neo4j. It aims to be a simple and intuitive way to migrate your database.
116 lines (115 loc) • 5.43 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@oclif/core");
const fs = __importStar(require("fs-extra"));
const base_command_1 = require("../base-command");
const connection_1 = require("../neo4j/connection");
const file_service_1 = require("../services/file.service");
const logger_1 = require("../services/logger");
const neo4j_repository_1 = require("../services/neo4j.repository");
const validate_service_1 = require("../services/validate.service");
class Validate extends base_command_1.BaseCommand {
static description = `Validate migration state between local files and database
Validates that all migrations in the migrations folder have been applied to the database
in the correct order and with matching checksums. Reports discrepancies.`;
static examples = [
'<%= config.bin %> validate',
'<%= config.bin %> validate -m ~/path/to/migrations',
'<%= config.bin %> validate --config ./custom-config.json',
'<%= config.bin %> validate --fail-fast',
'<%= config.bin %> validate --summary-only',
'<%= config.bin %> validate --output-file=validation-report.json',
'<%= config.bin %> validate --debug',
];
static flags = {
...base_command_1.BaseCommand.flags,
'fail-fast': core_1.Flags.boolean({
default: false,
description: 'Exit with error code on first validation failure',
}),
'output-file': core_1.Flags.string({
char: 'o',
description: 'Write detailed validation results to a JSON file',
}),
'summary-only': core_1.Flags.boolean({
default: false,
description: 'Show only the summary of validation failures',
}),
};
async run() {
try {
const { flags } = await this.parse(Validate);
const config = this.getConfig();
const connection = await (0, connection_1.getDatabaseConnection)(config);
const repository = new neo4j_repository_1.Repository(connection);
const fileService = new file_service_1.FileService(config);
const result = await new validate_service_1.ValidateService(repository, fileService).validate({
failFast: flags['fail-fast'],
summaryOnly: flags['summary-only'],
});
if (flags['output-file']) {
const outputPath = flags['output-file'];
try {
const failuresByType = {};
for (const failure of result.failures) {
if (!failuresByType[failure.type]) {
failuresByType[failure.type] = [];
}
failuresByType[failure.type].push({
message: failure.message,
severity: failure.severity,
version: failure.version || 'N/A',
});
}
const report = {
details: failuresByType,
metadata: {
databaseUri: `${config.scheme}://${config.host}:${config.port}`,
migrationsPath: config.migrationsPath,
timestamp: new Date().toISOString(),
},
summary: {
failuresByType: Object.fromEntries(Object.entries(failuresByType).map(([type, failures]) => [type, failures.length])),
isValid: result.isValid,
totalFailures: result.failures.length,
},
};
await fs.writeJSON(outputPath, report, { spaces: 2 });
logger_1.Logger.info(`Detailed validation report written to: ${outputPath}`);
}
catch (error) {
logger_1.Logger.error(`Failed to write validation report to file: ${error instanceof Error ? error.message : String(error)}`);
}
}
await connection.close();
}
catch (error) {
this.error(error instanceof Error ? error.message : String(error));
}
}
}
exports.default = Validate;
//# sourceMappingURL=validate.js.map