UNPKG

morpheus4j

Version:

Morpheus is a migration tool for Neo4j. It aims to be a simple and intuitive way to migrate your database.

62 lines 3.18 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MorpheusService = void 0; const common_1 = require("@nestjs/common"); const constants_1 = require("../constants"); const connection_1 = require("../neo4j/connection"); const clean_service_1 = require("../services/clean.service"); const config_service_1 = require("../services/config.service"); const file_service_1 = require("../services/file.service"); const migrate_service_1 = require("../services/migrate.service"); const neo4j_repository_1 = require("../services/neo4j.repository"); let MorpheusService = class MorpheusService { async cleanDatabase(config) { const finalConfig = await this.getConfig(config); const dropConstraints = Boolean(config?.cleanConfig?.dropConstraints); await this.withDatabaseConnection(async (repository) => { await new clean_service_1.CleanService(repository).clean(dropConstraints); }, finalConfig); } async runMigrations(config) { const finalConfig = await this.getConfig(config); const fileService = new file_service_1.FileService(finalConfig); await this.withDatabaseConnection(async (repository) => { await new migrate_service_1.MigrationService(repository, fileService).migrate(); }, finalConfig); } async getConfig(providedConfig) { if (providedConfig) { return providedConfig; } return config_service_1.ConfigService.load({ database: process.env[constants_1.EnvKeys.DATABASE], host: process.env[constants_1.EnvKeys.HOST], migrationsPath: process.env[constants_1.EnvKeys.MIGRATIONS_PATH], password: process.env[constants_1.EnvKeys.PASSWORD], port: process.env[constants_1.EnvKeys.PORT] ? Number(process.env[constants_1.EnvKeys.PORT]) : undefined, scheme: process.env[constants_1.EnvKeys.SCHEME], username: process.env[constants_1.EnvKeys.USERNAME], }, constants_1.MORPHEUS_FILE_NAME); } async withDatabaseConnection(operation, config) { const connection = await (0, connection_1.getDatabaseConnection)(config); const repository = new neo4j_repository_1.Repository(connection); try { return await operation(repository); } finally { await connection.close(); } } }; exports.MorpheusService = MorpheusService; exports.MorpheusService = MorpheusService = __decorate([ (0, common_1.Injectable)() ], MorpheusService); //# sourceMappingURL=morpheus.service.js.map