From 2dce8c841d9fb86d6fcf0878048d85c29c1be69c Mon Sep 17 00:00:00 2001 From: Claudemir Todo Bom Date: Sun, 10 Nov 2024 08:40:58 -0300 Subject: [PATCH] fix some migrations / transactions and db:migrate:undo:all --- ...changes-messages-and-oldmessages-tables.ts | 59 +++++++++++++------ ...504105300-add-paymentfields-to-invoices.ts | 47 ++++++++++----- ...20240507112700-add-queue-options-fields.ts | 38 ++++++++---- ...0240522165800-add-disablebot-to-contact.ts | 16 ++--- .../20240524011900-add-presence-to-contact.ts | 14 ++--- ...40814111700-create-user-socket-sessions.ts | 4 +- 6 files changed, 114 insertions(+), 64 deletions(-) diff --git a/backend/src/database/migrations/20240418173900-changes-messages-and-oldmessages-tables.ts b/backend/src/database/migrations/20240418173900-changes-messages-and-oldmessages-tables.ts index b0eb7074..f32d40d9 100644 --- a/backend/src/database/migrations/20240418173900-changes-messages-and-oldmessages-tables.ts +++ b/backend/src/database/migrations/20240418173900-changes-messages-and-oldmessages-tables.ts @@ -1,23 +1,39 @@ import { QueryInterface, DataTypes } from "sequelize"; -module.exports = { +export default { up: async (queryInterface: QueryInterface) => { const transaction = await queryInterface.sequelize.transaction(); try { - await queryInterface.removeConstraint("Messages", "Messages_quotedMsgId_fkey"); - await queryInterface.removeConstraint("OldMessages", "OldMessages_messageId_fkey"); - await queryInterface.removeConstraint("Messages", "Messages_pkey"); + await queryInterface.removeConstraint( + "Messages", + "Messages_quotedMsgId_fkey", + { transaction } + ); + await queryInterface.removeConstraint( + "OldMessages", + "OldMessages_messageId_fkey", + { transaction } + ); + await queryInterface.removeConstraint("Messages", "Messages_pkey", { + transaction + }); await queryInterface.addConstraint("Messages", { fields: ["id", "ticketId"], type: "primary key", - name: "Messges_id_ticketId_pk" - }); - await queryInterface.addColumn("OldMessages", "ticketId", { - type: DataTypes.INTEGER, - references: { model: "Tickets", key: "id" }, - onUpdate: "CASCADE", - onDelete: "SET NULL" + name: "Messges_id_ticketId_pk", + transaction }); + await queryInterface.addColumn( + "OldMessages", + "ticketId", + { + type: DataTypes.INTEGER, + references: { model: "Tickets", key: "id" }, + onUpdate: "CASCADE", + onDelete: "SET NULL" + }, + { transaction } + ); await transaction.commit(); } catch (err) { await transaction.rollback(); @@ -28,12 +44,19 @@ module.exports = { down: async (queryInterface: QueryInterface) => { const transaction = await queryInterface.sequelize.transaction(); try { - await queryInterface.removeColumn("OldMessages", "ticketId"); - await queryInterface.removeConstraint("Messages", "Messges_id_ticketId_pk"); + await queryInterface.removeColumn("OldMessages", "ticketId", { + transaction + }); + await queryInterface.removeConstraint( + "Messages", + "Messges_id_ticketId_pk", + { transaction } + ); await queryInterface.addConstraint("Messages", { fields: ["id"], type: "primary key", - name: "Messages_pkey" + name: "Messages_pkey", + transaction }); await queryInterface.addConstraint("OldMessages", { fields: ["messageId"], @@ -44,7 +67,8 @@ module.exports = { field: "id" }, onDelete: "CASCADE", - onUpdate: "CASCADE" + onUpdate: "CASCADE", + transaction }); await queryInterface.addConstraint("Messages", { fields: ["quotedMsgId"], @@ -55,7 +79,8 @@ module.exports = { field: "id" }, onDelete: "SET NULL", - onUpdate: "CASCADE" + onUpdate: "CASCADE", + transaction }); await transaction.commit(); } catch (err) { @@ -63,4 +88,4 @@ module.exports = { throw err; } } -}; \ No newline at end of file +}; diff --git a/backend/src/database/migrations/20240504105300-add-paymentfields-to-invoices.ts b/backend/src/database/migrations/20240504105300-add-paymentfields-to-invoices.ts index c73a962c..abc463de 100644 --- a/backend/src/database/migrations/20240504105300-add-paymentfields-to-invoices.ts +++ b/backend/src/database/migrations/20240504105300-add-paymentfields-to-invoices.ts @@ -1,22 +1,37 @@ import { QueryInterface, DataTypes } from "sequelize"; -module.exports = { +export default { up: async (queryInterface: QueryInterface) => { const transaction = await queryInterface.sequelize.transaction(); try { - await queryInterface.addColumn("Invoices", "txId", { - type: DataTypes.STRING, - - }); - await queryInterface.addColumn("Invoices", "payGw", { - type: DataTypes.STRING, - }); - await queryInterface.addColumn("Invoices", "payGwData", { - type: DataTypes.TEXT, - }); - await queryInterface.addIndex("Invoices", [ "txId" ], { + await queryInterface.addColumn( + "Invoices", + "txId", + { + type: DataTypes.STRING + }, + { transaction } + ); + await queryInterface.addColumn( + "Invoices", + "payGw", + { + type: DataTypes.STRING + }, + { transaction } + ); + await queryInterface.addColumn( + "Invoices", + "payGwData", + { + type: DataTypes.TEXT + }, + { transaction } + ); + await queryInterface.addIndex("Invoices", ["txId"], { name: "idx_txid", unique: false, + transaction }); await transaction.commit(); } catch (err) { @@ -28,9 +43,11 @@ module.exports = { down: async (queryInterface: QueryInterface) => { const transaction = await queryInterface.sequelize.transaction(); try { - await queryInterface.removeColumn("Invoices", "txId"); - await queryInterface.removeColumn("Invoices", "payGw"); - await queryInterface.removeColumn("Invoices", "payGwData"); + await queryInterface.removeColumn("Invoices", "txId", { transaction }); + await queryInterface.removeColumn("Invoices", "payGw", { transaction }); + await queryInterface.removeColumn("Invoices", "payGwData", { + transaction + }); await transaction.commit(); } catch (err) { await transaction.rollback(); diff --git a/backend/src/database/migrations/20240507112700-add-queue-options-fields.ts b/backend/src/database/migrations/20240507112700-add-queue-options-fields.ts index a7aea9ba..8d9ec14e 100644 --- a/backend/src/database/migrations/20240507112700-add-queue-options-fields.ts +++ b/backend/src/database/migrations/20240507112700-add-queue-options-fields.ts @@ -1,18 +1,28 @@ import { QueryInterface, DataTypes } from "sequelize"; -module.exports = { +export default { up: async (queryInterface: QueryInterface) => { const transaction = await queryInterface.sequelize.transaction(); try { - await queryInterface.addColumn("QueueOptions", "forwardQueueId", { - type: DataTypes.INTEGER, - references: { model: "Queues", key: "id" }, - allowNull: true, - }); - await queryInterface.addColumn("QueueOptions", "exitChatbot", { - type: DataTypes.BOOLEAN, - defaultValue: false, - }); + await queryInterface.addColumn( + "QueueOptions", + "forwardQueueId", + { + type: DataTypes.INTEGER, + references: { model: "Queues", key: "id" }, + allowNull: true + }, + { transaction } + ); + await queryInterface.addColumn( + "QueueOptions", + "exitChatbot", + { + type: DataTypes.BOOLEAN, + defaultValue: false + }, + { transaction } + ); await transaction.commit(); } catch (err) { @@ -24,8 +34,12 @@ module.exports = { down: async (queryInterface: QueryInterface) => { const transaction = await queryInterface.sequelize.transaction(); try { - await queryInterface.removeColumn("QueueOptions", "forwardQueueId"); - await queryInterface.removeColumn("QueueOptions", "exitChatbot"); + await queryInterface.removeColumn("QueueOptions", "forwardQueueId", { + transaction + }); + await queryInterface.removeColumn("QueueOptions", "exitChatbot", { + transaction + }); await transaction.commit(); } catch (err) { await transaction.rollback(); diff --git a/backend/src/database/migrations/20240522165800-add-disablebot-to-contact.ts b/backend/src/database/migrations/20240522165800-add-disablebot-to-contact.ts index fded9111..7c71ea49 100644 --- a/backend/src/database/migrations/20240522165800-add-disablebot-to-contact.ts +++ b/backend/src/database/migrations/20240522165800-add-disablebot-to-contact.ts @@ -1,18 +1,14 @@ import { QueryInterface, DataTypes } from "sequelize"; -module.exports = { +export default { up: (queryInterface: QueryInterface) => { - return Promise.all([ - queryInterface.addColumn("Contacts", "disableBot", { - type: DataTypes.BOOLEAN, - defaultValue: false - }), - ]); + return queryInterface.addColumn("Contacts", "disableBot", { + type: DataTypes.BOOLEAN, + defaultValue: false + }); }, down: (queryInterface: QueryInterface) => { - Promise.all([ - queryInterface.removeColumn("Contacts", "disableBot"), - ]); + return queryInterface.removeColumn("Contacts", "disableBot"); } }; diff --git a/backend/src/database/migrations/20240524011900-add-presence-to-contact.ts b/backend/src/database/migrations/20240524011900-add-presence-to-contact.ts index 83752c35..6a298a25 100644 --- a/backend/src/database/migrations/20240524011900-add-presence-to-contact.ts +++ b/backend/src/database/migrations/20240524011900-add-presence-to-contact.ts @@ -1,16 +1,14 @@ import { QueryInterface, DataTypes } from "sequelize"; -module.exports = { +export default { up: (queryInterface: QueryInterface) => { - return Promise.all([ - queryInterface.addColumn("Contacts", "presence", { - type: DataTypes.STRING, - defaultValue: "available" - }) - ]); + return queryInterface.addColumn("Contacts", "presence", { + type: DataTypes.STRING, + defaultValue: "available" + }); }, down: (queryInterface: QueryInterface) => { - Promise.all([queryInterface.removeColumn("Contacts", "presence")]); + return queryInterface.removeColumn("Contacts", "presence"); } }; diff --git a/backend/src/database/migrations/20240814111700-create-user-socket-sessions.ts b/backend/src/database/migrations/20240814111700-create-user-socket-sessions.ts index 89f9dd35..d772a4ef 100644 --- a/backend/src/database/migrations/20240814111700-create-user-socket-sessions.ts +++ b/backend/src/database/migrations/20240814111700-create-user-socket-sessions.ts @@ -1,6 +1,6 @@ import { QueryInterface, DataTypes } from "sequelize"; -module.exports = { +export default { up: (queryInterface: QueryInterface) => { return queryInterface.createTable("UserSocketSessions", { id: { @@ -31,6 +31,6 @@ module.exports = { }, down: (queryInterface: QueryInterface) => { - return queryInterface.dropTable("UserSocketSessios"); + return queryInterface.dropTable("UserSocketSessions"); } };