UNPKG

ddl-manager

Version:

store postgres procedures and triggers in files

51 lines 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FunctionsMigrator = void 0; const AbstractMigrator_1 = require("./AbstractMigrator"); class FunctionsMigrator extends AbstractMigrator_1.AbstractMigrator { async drop() { await this.dropFunctions(); } async create() { await this.createFunctions(); } async createLogFuncs() { for (const func of this.migration.toCreate.functions) { try { await this.postgres.createOrReplaceLogFunction(func); } catch (error) { this.onError(func, error); } } } async dropFunctions() { for (const func of this.migration.toDrop.functions) { // 2BP01 try { await this.postgres.dropFunction(func); } catch (error) { // https://www.postgresql.org/docs/12/errcodes-appendix.html // cannot drop function my_func() because other objects depend on it const isCascadeError = error.code === "2BP01"; if (!isCascadeError) { this.onError(func, error); } } } } async createFunctions() { for (const func of this.migration.toCreate.functions) { try { await this.postgres.createOrReplaceFunction(func); } catch (error) { console.log(error); this.onError(func, error); } } } } exports.FunctionsMigrator = FunctionsMigrator; //# sourceMappingURL=FunctionsMigrator.js.map