UNPKG

ddl-manager

Version:

store postgres procedures and triggers in files

74 lines 3.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MainMigrator = void 0; const FunctionsMigrator_1 = require("./FunctionsMigrator"); const TriggersMigrator_1 = require("./TriggersMigrator"); const ColumnsMigrator_1 = require("./ColumnsMigrator"); const UpdateMigrator_1 = require("./UpdateMigrator"); const IndexesMigrator_1 = require("./IndexesMigrator"); class MainMigrator { constructor(postgres, database, migration, outputErrors = [], aborted = false) { this.postgres = postgres; this.database = database; this.migration = migration; this.outputErrors = outputErrors; this.aborted = aborted; this.functions = new FunctionsMigrator_1.FunctionsMigrator(this.postgres, this.migration, this.database, this.outputErrors); this.triggers = new TriggersMigrator_1.TriggersMigrator(this.postgres, this.migration, this.database, this.outputErrors); this.columns = new ColumnsMigrator_1.ColumnsMigrator(this.postgres, this.migration, this.database, this.outputErrors); this.updates = new UpdateMigrator_1.UpdateMigrator(this.postgres, this.migration, this.database, this.outputErrors); this.indexes = new IndexesMigrator_1.IndexesMigrator(this.postgres, this.migration, this.database, this.outputErrors); } static async migrate(postgres, database, migration) { const migrator = new MainMigrator(postgres, database, migration); return await migrator.migrate(); } async migrate() { await this.dropOld(); await this.createNew(); return this.outputErrors; } async dropOld() { var _a, _b, _c, _d; await ((_a = this.triggers) === null || _a === void 0 ? void 0 : _a.drop()); await ((_b = this.functions) === null || _b === void 0 ? void 0 : _b.drop()); await ((_c = this.indexes) === null || _c === void 0 ? void 0 : _c.drop()); await ((_d = this.columns) === null || _d === void 0 ? void 0 : _d.drop()); return this.outputErrors; } async createNew() { var _a, _b, _c, _d, _e; await ((_a = this.columns) === null || _a === void 0 ? void 0 : _a.create()); await ((_b = this.functions) === null || _b === void 0 ? void 0 : _b.create()); await ((_c = this.triggers) === null || _c === void 0 ? void 0 : _c.create()); await ((_d = this.indexes) === null || _d === void 0 ? void 0 : _d.create()); await ((_e = this.updates) === null || _e === void 0 ? void 0 : _e.create()); return this.outputErrors; } async buildNewColumnsAndFunctions() { var _a, _b, _c, _d; await ((_a = this.columns) === null || _a === void 0 ? void 0 : _a.create()); await ((_b = this.functions) === null || _b === void 0 ? void 0 : _b.create()); await ((_c = this.triggers) === null || _c === void 0 ? void 0 : _c.create()); await ((_d = this.indexes) === null || _d === void 0 ? void 0 : _d.create()); return this.outputErrors; } abort() { var _a; if (this.isAborted()) { return; } this.aborted = true; (_a = this.updates) === null || _a === void 0 ? void 0 : _a.abort(); this.triggers = undefined; this.functions = undefined; this.columns = undefined; this.indexes = undefined; this.updates = undefined; } isAborted() { return this.aborted; } } exports.MainMigrator = MainMigrator; //# sourceMappingURL=MainMigrator.js.map