|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +const TABLE_NAME = "CCCChanges"; |
| 4 | +module.exports = { |
| 5 | + up: async (queryInterface, Sequelize) => { |
| 6 | + await Promise.all([ |
| 7 | + queryInterface.removeConstraint( |
| 8 | + TABLE_NAME, |
| 9 | + "ccc_changes_change_constraint" |
| 10 | + ), |
| 11 | + queryInterface.removeConstraint( |
| 12 | + TABLE_NAME, |
| 13 | + "ccc_changes_transaction_hash_constraint" |
| 14 | + ), |
| 15 | + queryInterface.removeConstraint( |
| 16 | + TABLE_NAME, |
| 17 | + "ccc_changes_block_number_constraint" |
| 18 | + ) |
| 19 | + ]); |
| 20 | + await queryInterface.sequelize.query( |
| 21 | + `ALTER TYPE "enum_CCCChanges_reason" ADD VALUE 'report' AFTER 'validator'` |
| 22 | + ); |
| 23 | + await Promise.all([ |
| 24 | + queryInterface.addConstraint(TABLE_NAME, ["change"], { |
| 25 | + type: "check", |
| 26 | + name: "ccc_changes_change_constraint", |
| 27 | + where: { |
| 28 | + [Sequelize.Op.or]: [ |
| 29 | + { |
| 30 | + reason: ["fee"], |
| 31 | + change: { [Sequelize.Op.lt]: 0 } |
| 32 | + }, |
| 33 | + { |
| 34 | + reason: [ |
| 35 | + "author", |
| 36 | + "stake", |
| 37 | + "initial_distribution", |
| 38 | + "validator", |
| 39 | + "report" |
| 40 | + ], |
| 41 | + change: { [Sequelize.Op.gt]: 0 } |
| 42 | + }, |
| 43 | + { |
| 44 | + reason: ["tx", "deposit"] |
| 45 | + } |
| 46 | + ] |
| 47 | + } |
| 48 | + }), |
| 49 | + queryInterface.addConstraint(TABLE_NAME, ["transactionHash"], { |
| 50 | + type: "check", |
| 51 | + name: "ccc_changes_transaction_hash_constraint", |
| 52 | + where: { |
| 53 | + [Sequelize.Op.or]: [ |
| 54 | + { |
| 55 | + reason: [ |
| 56 | + "author", |
| 57 | + "stake", |
| 58 | + "initial_distribution", |
| 59 | + "deposit", |
| 60 | + "validator" |
| 61 | + ], |
| 62 | + transactionHash: { [Sequelize.Op.eq]: null } |
| 63 | + }, |
| 64 | + { |
| 65 | + reason: ["fee", "tx", "deposit", "report"], |
| 66 | + transactionHash: { [Sequelize.Op.ne]: null } |
| 67 | + } |
| 68 | + ] |
| 69 | + } |
| 70 | + }), |
| 71 | + queryInterface.addConstraint(TABLE_NAME, ["blockNumber"], { |
| 72 | + type: "check", |
| 73 | + name: "ccc_changes_block_number_constraint", |
| 74 | + where: { |
| 75 | + [Sequelize.Op.or]: [ |
| 76 | + { |
| 77 | + reason: ["initial_distribution"], |
| 78 | + blockNumber: { [Sequelize.Op.eq]: 0 } |
| 79 | + }, |
| 80 | + { |
| 81 | + reason: [ |
| 82 | + "author", |
| 83 | + "stake", |
| 84 | + "fee", |
| 85 | + "tx", |
| 86 | + "deposit", |
| 87 | + "validator", |
| 88 | + "report" |
| 89 | + ], |
| 90 | + blockNumber: { [Sequelize.Op.gt]: 0 } |
| 91 | + } |
| 92 | + ] |
| 93 | + } |
| 94 | + }) |
| 95 | + ]); |
| 96 | + }, |
| 97 | + |
| 98 | + down: async (queryInterface, Sequelize) => { |
| 99 | + await Promise.all([ |
| 100 | + queryInterface.removeIndex(TABLE_NAME, "ccc_changes_unique_index"), |
| 101 | + queryInterface.removeIndex(TABLE_NAME, "ccc_changes_unique_index2"), |
| 102 | + queryInterface.removeConstraint( |
| 103 | + TABLE_NAME, |
| 104 | + "ccc_changes_change_constraint" |
| 105 | + ), |
| 106 | + queryInterface.removeConstraint( |
| 107 | + TABLE_NAME, |
| 108 | + "ccc_changes_transaction_hash_constraint" |
| 109 | + ), |
| 110 | + queryInterface.removeConstraint( |
| 111 | + TABLE_NAME, |
| 112 | + "ccc_changes_block_number_constraint" |
| 113 | + ) |
| 114 | + ]); |
| 115 | + |
| 116 | + await queryInterface.sequelize.query( |
| 117 | + `ALTER TYPE "enum_CCCChanges_reason" RENAME TO "enum_CCCChanges_reason_tmp"` |
| 118 | + ); |
| 119 | + await queryInterface.sequelize.query( |
| 120 | + `CREATE TYPE "enum_CCCChanges_reason" AS ENUM ('fee', 'author', 'stake', 'tx', 'initial_distribution', 'deposit', 'validator')` |
| 121 | + ); |
| 122 | + await queryInterface.sequelize.query( |
| 123 | + `ALTER TABLE "${TABLE_NAME}" ALTER "reason" TYPE "enum_CCCChanges_reason" USING "reason"::text::"enum_CCCChanges_reason"` |
| 124 | + ); |
| 125 | + await queryInterface.sequelize.query( |
| 126 | + `DROP TYPE "enum_CCCChanges_reason_tmp"` |
| 127 | + ); |
| 128 | + |
| 129 | + return Promise.all([ |
| 130 | + queryInterface.addIndex( |
| 131 | + TABLE_NAME, |
| 132 | + ["address", "blockNumber", "reason", "transactionHash"], |
| 133 | + { |
| 134 | + name: "ccc_changes_unique_index", |
| 135 | + unique: true |
| 136 | + } |
| 137 | + ), |
| 138 | + queryInterface.addIndex( |
| 139 | + TABLE_NAME, |
| 140 | + ["address", "blockNumber", "reason"], |
| 141 | + { |
| 142 | + unique: true, |
| 143 | + name: "ccc_changes_unique_index2", |
| 144 | + where: { |
| 145 | + reason: [ |
| 146 | + "author", |
| 147 | + "stake", |
| 148 | + "initial_distribution", |
| 149 | + "deposit" |
| 150 | + ] |
| 151 | + } |
| 152 | + } |
| 153 | + ), |
| 154 | + queryInterface.addConstraint(TABLE_NAME, ["change"], { |
| 155 | + type: "check", |
| 156 | + name: "ccc_changes_change_constraint", |
| 157 | + where: { |
| 158 | + [Sequelize.Op.or]: [ |
| 159 | + { |
| 160 | + reason: ["fee"], |
| 161 | + change: { [Sequelize.Op.lt]: 0 } |
| 162 | + }, |
| 163 | + { |
| 164 | + reason: [ |
| 165 | + "author", |
| 166 | + "stake", |
| 167 | + "initial_distribution", |
| 168 | + "validator" |
| 169 | + ], |
| 170 | + change: { [Sequelize.Op.gt]: 0 } |
| 171 | + }, |
| 172 | + { |
| 173 | + reason: ["tx", "deposit"] |
| 174 | + } |
| 175 | + ] |
| 176 | + } |
| 177 | + }), |
| 178 | + queryInterface.addConstraint(TABLE_NAME, ["transactionHash"], { |
| 179 | + type: "check", |
| 180 | + name: "ccc_changes_transaction_hash_constraint", |
| 181 | + where: { |
| 182 | + [Sequelize.Op.or]: [ |
| 183 | + { |
| 184 | + reason: [ |
| 185 | + "author", |
| 186 | + "stake", |
| 187 | + "initial_distribution", |
| 188 | + "deposit", |
| 189 | + "validator" |
| 190 | + ], |
| 191 | + transactionHash: { [Sequelize.Op.eq]: null } |
| 192 | + }, |
| 193 | + { |
| 194 | + reason: ["fee", "tx", "deposit"], |
| 195 | + transactionHash: { [Sequelize.Op.ne]: null } |
| 196 | + } |
| 197 | + ] |
| 198 | + } |
| 199 | + }), |
| 200 | + queryInterface.addConstraint(TABLE_NAME, ["blockNumber"], { |
| 201 | + type: "check", |
| 202 | + name: "ccc_changes_block_number_constraint", |
| 203 | + where: { |
| 204 | + [Sequelize.Op.or]: [ |
| 205 | + { |
| 206 | + reason: ["initial_distribution"], |
| 207 | + blockNumber: { [Sequelize.Op.eq]: 0 } |
| 208 | + }, |
| 209 | + { |
| 210 | + reason: [ |
| 211 | + "author", |
| 212 | + "stake", |
| 213 | + "fee", |
| 214 | + "tx", |
| 215 | + "deposit", |
| 216 | + "validator" |
| 217 | + ], |
| 218 | + blockNumber: { [Sequelize.Op.gt]: 0 } |
| 219 | + } |
| 220 | + ] |
| 221 | + } |
| 222 | + }) |
| 223 | + ]); |
| 224 | + } |
| 225 | +}; |
0 commit comments