|
| 1 | +/** |
| 2 | + * @typedef {import('typeorm').MigrationInterface} MigrationInterface |
| 3 | + * @typedef {import('typeorm').QueryRunner} QueryRunner |
| 4 | + */ |
| 5 | + |
| 6 | +/** |
| 7 | + * Recalibrate financeLogPairIds for toScrypt CHF. |
| 8 | + * |
| 9 | + * BankTx 190079 (19.02, 40k CHF) has no matching ExchangeTx deposit at Scrypt |
| 10 | + * because it was manually added, shifting the 1:1 mapping. In unfiltered mode |
| 11 | + * there are 23 senders (40k each) vs 22 receivers (40k each) → +40'000 CHF |
| 12 | + * phantom pending on Yapeal/CHF (Asset 404). |
| 13 | + * |
| 14 | + * Fix: Set both IDs so the unfiltered window starts balanced |
| 15 | + * (Sender = 1'370'000 CHF, Receiver = 1'370'000 CHF → toScrypt = 0). |
| 16 | + * |
| 17 | + * @class |
| 18 | + * @implements {MigrationInterface} |
| 19 | + */ |
| 20 | +module.exports = class RecalibrateScryptChfPairIds1772500000000 { |
| 21 | + name = 'RecalibrateScryptChfPairIds1772500000000'; |
| 22 | + |
| 23 | + /** |
| 24 | + * @param {QueryRunner} queryRunner |
| 25 | + */ |
| 26 | + async up(queryRunner) { |
| 27 | + console.log('=== Recalibrate financeLogPairIds toScrypt CHF ===\n'); |
| 28 | + |
| 29 | + const rows = await queryRunner.query(`SELECT id, value FROM dbo.setting WHERE [key] = 'financeLogPairIds'`); |
| 30 | + |
| 31 | + if (rows.length === 0) { |
| 32 | + console.log('ERROR: financeLogPairIds setting not found. Aborting.'); |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + const setting = rows[0]; |
| 37 | + const pairIds = JSON.parse(setting.value); |
| 38 | + |
| 39 | + console.log('Current toScrypt.chf:', JSON.stringify(pairIds.toScrypt.chf)); |
| 40 | + |
| 41 | + pairIds.toScrypt.chf.bankTxId = 190080; |
| 42 | + pairIds.toScrypt.chf.exchangeTxId = 123646; |
| 43 | + |
| 44 | + console.log('New toScrypt.chf:', JSON.stringify(pairIds.toScrypt.chf)); |
| 45 | + |
| 46 | + const newValue = JSON.stringify(pairIds); |
| 47 | + |
| 48 | + await queryRunner.query(`UPDATE dbo.setting SET value = '${newValue}' WHERE id = ${setting.id}`); |
| 49 | + |
| 50 | + // Verify |
| 51 | + const verify = await queryRunner.query(`SELECT value FROM dbo.setting WHERE id = ${setting.id}`); |
| 52 | + const verified = JSON.parse(verify[0].value); |
| 53 | + console.log('\nVerified toScrypt.chf:', JSON.stringify(verified.toScrypt.chf)); |
| 54 | + console.log('\n=== Migration Complete ==='); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * @param {QueryRunner} queryRunner |
| 59 | + */ |
| 60 | + async down(queryRunner) { |
| 61 | + const rows = await queryRunner.query(`SELECT id, value FROM dbo.setting WHERE [key] = 'financeLogPairIds'`); |
| 62 | + |
| 63 | + if (rows.length === 0) return; |
| 64 | + |
| 65 | + const setting = rows[0]; |
| 66 | + const pairIds = JSON.parse(setting.value); |
| 67 | + |
| 68 | + pairIds.toScrypt.chf.bankTxId = 186482; |
| 69 | + pairIds.toScrypt.chf.exchangeTxId = 116514; |
| 70 | + |
| 71 | + await queryRunner.query(`UPDATE dbo.setting SET value = '${JSON.stringify(pairIds)}' WHERE id = ${setting.id}`); |
| 72 | + } |
| 73 | +}; |
0 commit comments