UNPKG

@wocker/pgsql-plugin

Version:
238 lines (237 loc) 11 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; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PgSqlController = void 0; const core_1 = require("@wocker/core"); const PgSqlService_1 = require("../services/PgSqlService"); let PgSqlController = class PgSqlController { constructor(appConfigService, dockerService, pgSqlService) { this.appConfigService = appConfigService; this.dockerService = dockerService; this.pgSqlService = pgSqlService; } init(adminEnabled, adminDisabled, email, password, skipPassword) { return __awaiter(this, void 0, void 0, function* () { yield this.pgSqlService.init({ enabled: adminEnabled === true ? true : adminDisabled === true ? false : undefined, email, password, skipPassword }); yield this.pgSqlService.admin(); }); } pgsql(name) { return __awaiter(this, void 0, void 0, function* () { yield this.pgSqlService.pgsql(name); }); } dump(name) { return __awaiter(this, void 0, void 0, function* () { yield this.pgSqlService.dump(name); }); } create(name, user, password, host, port, imageName, imageVersion, containerPort) { return __awaiter(this, void 0, void 0, function* () { yield this.pgSqlService.create({ name, user, password, host, port, imageName, imageVersion, containerPort }); if (host) { yield this.pgSqlService.admin(); } }); } upgrade(name, imageName, imageVersion, containerPort) { return __awaiter(this, void 0, void 0, function* () { yield this.pgSqlService.upgrade({ name, imageName, imageVersion, containerPort }); }); } destroy(service, yes, force) { return __awaiter(this, void 0, void 0, function* () { yield this.pgSqlService.destroy(service, yes, force); yield this.pgSqlService.admin(); }); } list() { return __awaiter(this, void 0, void 0, function* () { return this.pgSqlService.listTable(); }); } start(service, restart) { return __awaiter(this, void 0, void 0, function* () { yield this.pgSqlService.start(service, restart); yield this.pgSqlService.admin(); }); } stop(service) { return __awaiter(this, void 0, void 0, function* () { yield this.pgSqlService.stop(service); yield this.pgSqlService.admin(); }); } default(service) { return __awaiter(this, void 0, void 0, function* () { yield this.pgSqlService.setDefault(service); }); } getServices() { return __awaiter(this, void 0, void 0, function* () { return this.pgSqlService.getServices(); }); } }; exports.PgSqlController = PgSqlController; __decorate([ (0, core_1.Command)("pgsql:init"), (0, core_1.Description)("Initializes PostgreSQL functionality and opens the admin interface. Optionally configures email and password."), __param(0, (0, core_1.Option)("admin-enabled")), __param(1, (0, core_1.Option)("admin-disabled")), __param(2, (0, core_1.Option)("email", "e")), __param(3, (0, core_1.Option)("password", "p")), __param(4, (0, core_1.Option)("skip-password", "s")), __metadata("design:type", Function), __metadata("design:paramtypes", [Boolean, Boolean, String, String, Boolean]), __metadata("design:returntype", Promise) ], PgSqlController.prototype, "init", null); __decorate([ (0, core_1.Command)("pgsql [service]"), (0, core_1.Description)("Interacts with a specified PostgreSQL service."), __param(0, (0, core_1.Param)("service")), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], PgSqlController.prototype, "pgsql", null); __decorate([ (0, core_1.Command)("pgsql:dump [service]"), (0, core_1.Description)("Creates a dump of the specified PostgreSQL service."), __param(0, (0, core_1.Param)("service")), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], PgSqlController.prototype, "dump", null); __decorate([ (0, core_1.Command)("pgsql:create <service>"), (0, core_1.Description)("Creates a PostgreSQL service with configurable user, password, host, and port options."), __param(0, (0, core_1.Param)("service")), __param(1, (0, core_1.Option)("user", "u")), __param(1, (0, core_1.Description)("User name")), __param(2, (0, core_1.Option)("password", "p")), __param(2, (0, core_1.Description)("Password")), __param(3, (0, core_1.Option)("host", "h")), __param(3, (0, core_1.Description)("External host")), __param(4, (0, core_1.Option)("port", "P")), __param(4, (0, core_1.Description)("External port")), __param(5, (0, core_1.Option)("image", "i")), __param(5, (0, core_1.Description)("Image name")), __param(6, (0, core_1.Option)("image-version", "I")), __param(6, (0, core_1.Description)("Image version")), __param(7, (0, core_1.Option)("container-port")), __param(7, (0, core_1.Description)("Port on which the database container will be accessible on the host")), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String, String, String, String, String, String, Number]), __metadata("design:returntype", Promise) ], PgSqlController.prototype, "create", null); __decorate([ (0, core_1.Command)("pgsql:upgrade [service]"), (0, core_1.Description)("Upgrades a PostgreSQL service with options to specify image and version."), __param(0, (0, core_1.Param)("service")), __param(1, (0, core_1.Option)("image", "i")), __param(1, (0, core_1.Description)("Image name")), __param(2, (0, core_1.Option)("image-version", "I")), __param(2, (0, core_1.Description)("Image version")), __param(3, (0, core_1.Option)("container-port")), __param(3, (0, core_1.Description)("Port on which the database container will be accessible on the host")), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String, String, Number]), __metadata("design:returntype", Promise) ], PgSqlController.prototype, "upgrade", null); __decorate([ (0, core_1.Command)("pgsql:destroy <service>"), (0, core_1.Description)("Destroys a specified PostgreSQL service."), __param(0, (0, core_1.Param)("service")), __param(1, (0, core_1.Option)("yes", "y")), __param(1, (0, core_1.Description)("Don't ask for confirmation")), __param(2, (0, core_1.Option)("force", "f")), __param(2, (0, core_1.Description)("Force destroy the service")), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Boolean, Boolean]), __metadata("design:returntype", Promise) ], PgSqlController.prototype, "destroy", null); __decorate([ (0, core_1.Command)("pgsql:ls"), (0, core_1.Description)("Lists all available PostgreSQL tables in the service."), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], PgSqlController.prototype, "list", null); __decorate([ (0, core_1.Command)("pgsql:start [service]"), (0, core_1.Description)("Starts the specified PostgreSQL service and opens the admin interface."), __param(0, (0, core_1.Param)("service")), __param(1, (0, core_1.Option)("restart", "r")), __param(1, (0, core_1.Description)("Restart the service if it's already running")), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Boolean]), __metadata("design:returntype", Promise) ], PgSqlController.prototype, "start", null); __decorate([ (0, core_1.Command)("pgsql:stop [service]"), (0, core_1.Description)("Stops a PostgreSQL service and opens the administration interface."), __param(0, (0, core_1.Param)("service")), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], PgSqlController.prototype, "stop", null); __decorate([ (0, core_1.Command)("pgsql:use <service>"), (0, core_1.Description)("Sets the specified PostgreSQL service as the default."), __param(0, (0, core_1.Param)("service")), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], PgSqlController.prototype, "default", null); __decorate([ (0, core_1.Completion)("service"), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], PgSqlController.prototype, "getServices", null); exports.PgSqlController = PgSqlController = __decorate([ (0, core_1.Controller)(), (0, core_1.Description)("PostgreSQL commands"), __metadata("design:paramtypes", [core_1.AppConfigService, core_1.DockerService, PgSqlService_1.PgSqlService]) ], PgSqlController);