morpheus4j
Version:
Morpheus is a migration tool for Neo4j. It aims to be a simple and intuitive way to migrate your database.
84 lines • 3.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.InfoService = void 0;
const types_1 = require("../types");
const logger_1 = require("./logger");
const utils_1 = require("./utils");
class InfoService {
repository;
fileService;
static MESSAGES = {
ERROR: 'Failed to retrieve migration information',
EXCESS_MIGRATIONS: 'There are more migrations in the database than in the migrations folder',
NO_MIGRATIONS: 'Database is up to date, but there are no migrations in the migrations folder',
};
constructor(repository, fileService) {
this.repository = repository;
this.fileService = fileService;
}
async getInfo() {
try {
const [state, files] = await Promise.all([
this.repository.getMigrationState(),
this.fileService.getFileNamesFromMigrationsFolder(),
]);
const { appliedMigrations } = state;
if (appliedMigrations.length > files.length) {
logger_1.Logger.error(InfoService.MESSAGES.EXCESS_MIGRATIONS);
this.printMigrationSummary(appliedMigrations);
return;
}
if (appliedMigrations.length === 0 && files.length === 0) {
logger_1.Logger.info(InfoService.MESSAGES.NO_MIGRATIONS);
return;
}
this.printDetailedMigrationTable(appliedMigrations, files);
}
catch (error) {
logger_1.Logger.error(InfoService.MESSAGES.ERROR);
throw this.wrapError(error);
}
}
printDetailedMigrationTable(migrations, files) {
const table = files
.map((fileName) => {
const version = this.fileService.getMigrationVersionFromFileName(fileName);
const appliedMigration = migrations.find((m) => m.node.version === version);
if (appliedMigration) {
return {
Description: appliedMigration.node.description,
ExecutionTime: (0, utils_1.convertInToTime)(appliedMigration.relation.in),
InstalledOn: (0, utils_1.convertAtToDate)(appliedMigration.relation.at).getTime(),
State: types_1.MigrationState.APPLIED,
Version: version,
};
}
return {
Description: this.fileService.getMigrationDescriptionFromFileName(fileName),
ExecutionTime: 'N/A',
InstalledOn: 'N/A',
State: types_1.MigrationState.PENDING,
Version: version,
};
})
.sort((a, b) => this.fileService.compareVersions(a.Version, b.Version));
console.table(table);
}
printMigrationSummary(migrations) {
logger_1.Logger.info('Existing migrations:');
const summary = migrations.map((migration) => ({
Description: migration.node.description,
Source: migration.node.source,
State: types_1.MigrationState.APPLIED,
Type: migration.node.type,
Version: migration.node.version,
}));
console.table(summary);
}
wrapError(error) {
const message = error instanceof Error ? error.message : String(error);
return new Error(`InfoService error: ${message}`);
}
}
exports.InfoService = InfoService;
//# sourceMappingURL=info.service.js.map