Skip to content

Commit

Permalink
fix some migrations / transactions and db:migrate:undo:all
Browse files Browse the repository at this point in the history
  • Loading branch information
allgood committed Nov 10, 2024
1 parent 685243e commit 2dce8c8
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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"],
Expand All @@ -44,7 +67,8 @@ module.exports = {
field: "id"
},
onDelete: "CASCADE",
onUpdate: "CASCADE"
onUpdate: "CASCADE",
transaction
});
await queryInterface.addConstraint("Messages", {
fields: ["quotedMsgId"],
Expand All @@ -55,12 +79,13 @@ module.exports = {
field: "id"
},
onDelete: "SET NULL",
onUpdate: "CASCADE"
onUpdate: "CASCADE",
transaction
});
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
}
};
};
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
};
Original file line number Diff line number Diff line change
@@ -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");
}
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { QueryInterface, DataTypes } from "sequelize";

module.exports = {
export default {
up: (queryInterface: QueryInterface) => {
return queryInterface.createTable("UserSocketSessions", {
id: {
Expand Down Expand Up @@ -31,6 +31,6 @@ module.exports = {
},

down: (queryInterface: QueryInterface) => {
return queryInterface.dropTable("UserSocketSessios");
return queryInterface.dropTable("UserSocketSessions");
}
};

0 comments on commit 2dce8c8

Please sign in to comment.