|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +/** @type {import('sequelize-cli').Migration} */ |
| 4 | +module.exports = { |
| 5 | + async up (queryInterface, Sequelize) { |
| 6 | + const transaction = await queryInterface.sequelize.transaction(); |
| 7 | + try { |
| 8 | + await queryInterface.sequelize.query(` |
| 9 | + ALTER TABLE token_transfers |
| 10 | + ADD CONSTRAINT "token_transfers_transactionId_fkey" |
| 11 | + FOREIGN KEY ("transactionId") |
| 12 | + REFERENCES transactions(id); |
| 13 | + `, { transaction }); |
| 14 | + |
| 15 | + await queryInterface.sequelize.query(` |
| 16 | + ALTER TABLE token_transfers |
| 17 | + ADD CONSTRAINT "token_transfers_transactionLogId_fkey" |
| 18 | + FOREIGN KEY ("transactionLogId") |
| 19 | + REFERENCES transaction_logs(id); |
| 20 | + `, { transaction }); |
| 21 | + |
| 22 | + await transaction.commit(); |
| 23 | + } catch(error) { |
| 24 | + console.log(error); |
| 25 | + await transaction.rollback(); |
| 26 | + throw error; |
| 27 | + } |
| 28 | + }, |
| 29 | + |
| 30 | + async down (queryInterface, Sequelize) { |
| 31 | + const transaction = await queryInterface.sequelize.transaction(); |
| 32 | + try { |
| 33 | + await queryInterface.sequelize.query(` |
| 34 | + ALTER TABLE token_transfers |
| 35 | + DROP CONSTRAINT "token_transfers_transactionId_fkey"; |
| 36 | + `, { transaction }); |
| 37 | + |
| 38 | + await queryInterface.sequelize.query(` |
| 39 | + ALTER TABLE token_transfers |
| 40 | + DROP CONSTRAINT "token_transfers_transactionLogId_fkey"; |
| 41 | + `, { transaction }); |
| 42 | + |
| 43 | + await transaction.commit(); |
| 44 | + } catch(error) { |
| 45 | + console.log(error); |
| 46 | + await transaction.rollback(); |
| 47 | + throw error; |
| 48 | + } |
| 49 | + } |
| 50 | +}; |
0 commit comments