@limlabs/limo
Version:
Infrastructure as Code generator
57 lines (56 loc) • 2.58 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.triggerMigration = exports.ensureMigrationNotApplied = exports.isMigrationApplied = void 0;
const data_1 = require("./data");
const operations_1 = __importDefault(require("./operations"));
const implementedOperations = [
"initResourceGroup",
"removeResourceGroup",
"configureFramework"
];
function isMigrationApplied(migration) {
return __awaiter(this, void 0, void 0, function* () {
const history = yield (0, data_1.getMigrationHistory)();
return history.migrations.includes(migration.id);
});
}
exports.isMigrationApplied = isMigrationApplied;
const ensureMigrationNotApplied = (migration) => __awaiter(void 0, void 0, void 0, function* () {
yield (0, data_1.ensureMigrations)();
const migrationApplied = yield isMigrationApplied(migration);
if (migrationApplied) {
throw `Migration ${migration.id} already applied`;
}
});
exports.ensureMigrationNotApplied = ensureMigrationNotApplied;
const triggerMigration = (migration, apply = true, cmdArgs) => __awaiter(void 0, void 0, void 0, function* () {
var _a;
if (apply) {
yield (0, exports.ensureMigrationNotApplied)(migration);
}
for (const operation of apply
? migration.up
: ((_a = migration.down) !== null && _a !== void 0 ? _a : []).reverse()) {
if (!operation.options) {
throw new Error(`Missing options for ${operation.type} operation`);
}
yield operations_1.default[operation.type]({
options: operation.options,
cmdArgs
});
}
yield (0, data_1.updateMigrationHistory)(migration.id, apply);
});
exports.triggerMigration = triggerMigration;