|
| 1 | +/** |
| 2 | + * @typedef {import('typeorm').MigrationInterface} MigrationInterface |
| 3 | + * @typedef {import('typeorm').QueryRunner} QueryRunner |
| 4 | + */ |
| 5 | + |
| 6 | +/** |
| 7 | + * Recalibrate financeLogPairIds for toScrypt EUR (second recalibration). |
| 8 | + * |
| 9 | + * The receiver side (eurReceiverScryptExchangeTx) includes ALL Scrypt EUR deposits, |
| 10 | + * while the sender side (eurSenderScryptBankTx) is filtered by eurBankIbans (Olkypay + |
| 11 | + * Yapeal only). Former MaerkiBaumann transfers (bank_tx 191068: 363k, 191069: 42k) |
| 12 | + * created exchange_tx deposits but are excluded from the bank_tx sender list, causing |
| 13 | + * a 281k EUR mismatch and a negative toScryptUnfiltered. |
| 14 | + * |
| 15 | + * Fix: Move the pair IDs forward to the latest settled pair: |
| 16 | + * bankTxId 191523 (30k EUR, Olkypay, Mar 4) |
| 17 | + * exchangeTxId 126558 (30k EUR, Scrypt DEPOSIT, Mar 4) |
| 18 | + * |
| 19 | + * This excludes orphan exchange_tx and MaerkiBaumann bank_tx from the window, |
| 20 | + * correctly showing only the pending 30k EUR transfer. |
| 21 | + * |
| 22 | + * @class |
| 23 | + * @implements {MigrationInterface} |
| 24 | + */ |
| 25 | +module.exports = class RecalibrateScryptEurPairIds1772600000000 { |
| 26 | + name = 'RecalibrateScryptEurPairIds1772600000000'; |
| 27 | + |
| 28 | + /** |
| 29 | + * @param {QueryRunner} queryRunner |
| 30 | + */ |
| 31 | + async up(queryRunner) { |
| 32 | + console.log('=== Recalibrate financeLogPairIds toScrypt EUR (2nd) ===\n'); |
| 33 | + |
| 34 | + const rows = await queryRunner.query( |
| 35 | + `SELECT id, value FROM dbo.setting WHERE [key] = 'financeLogPairIds'`, |
| 36 | + ); |
| 37 | + |
| 38 | + if (rows.length === 0) { |
| 39 | + console.log('ERROR: financeLogPairIds setting not found. Aborting.'); |
| 40 | + return; |
| 41 | + } |
| 42 | + |
| 43 | + const setting = rows[0]; |
| 44 | + const pairIds = JSON.parse(setting.value); |
| 45 | + |
| 46 | + console.log('Current toScrypt.eur:', JSON.stringify(pairIds.toScrypt.eur)); |
| 47 | + |
| 48 | + pairIds.toScrypt.eur.bankTxId = 191523; |
| 49 | + pairIds.toScrypt.eur.exchangeTxId = 126558; |
| 50 | + |
| 51 | + console.log('New toScrypt.eur:', JSON.stringify(pairIds.toScrypt.eur)); |
| 52 | + |
| 53 | + const newValue = JSON.stringify(pairIds); |
| 54 | + |
| 55 | + await queryRunner.query( |
| 56 | + `UPDATE dbo.setting SET value = '${newValue}' WHERE id = ${setting.id}`, |
| 57 | + ); |
| 58 | + |
| 59 | + // Verify |
| 60 | + const verify = await queryRunner.query( |
| 61 | + `SELECT value FROM dbo.setting WHERE id = ${setting.id}`, |
| 62 | + ); |
| 63 | + const verified = JSON.parse(verify[0].value); |
| 64 | + console.log('\nVerified toScrypt.eur:', JSON.stringify(verified.toScrypt.eur)); |
| 65 | + console.log('\n=== Migration Complete ==='); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * @param {QueryRunner} queryRunner |
| 70 | + */ |
| 71 | + async down(queryRunner) { |
| 72 | + const rows = await queryRunner.query( |
| 73 | + `SELECT id, value FROM dbo.setting WHERE [key] = 'financeLogPairIds'`, |
| 74 | + ); |
| 75 | + |
| 76 | + if (rows.length === 0) return; |
| 77 | + |
| 78 | + const setting = rows[0]; |
| 79 | + const pairIds = JSON.parse(setting.value); |
| 80 | + |
| 81 | + pairIds.toScrypt.eur.bankTxId = 190029; |
| 82 | + pairIds.toScrypt.eur.exchangeTxId = 123655; |
| 83 | + |
| 84 | + await queryRunner.query( |
| 85 | + `UPDATE dbo.setting SET value = '${JSON.stringify(pairIds)}' WHERE id = ${setting.id}`, |
| 86 | + ); |
| 87 | + } |
| 88 | +}; |
0 commit comments