|
| 1 | +/* eslint-disable camelcase */ |
| 2 | + |
| 3 | +exports.shorthands = undefined; |
| 4 | + |
| 5 | +function replaceIndex(pgm, table, column, method = 'btree') { |
| 6 | + pgm.dropIndex(table, column); |
| 7 | + pgm.createIndex(table, column, { method: method }); |
| 8 | +} |
| 9 | + |
| 10 | +exports.up = pgm => { |
| 11 | + pgm.dropIndex('txs', [{ name: 'tx_index', sort: 'DESC' }], { ifExists: true }); |
| 12 | + pgm.dropIndex('txs', 'tx_id', { ifExists: true }); |
| 13 | + replaceIndex(pgm, 'txs', 'token_transfer_recipient_address'); |
| 14 | + replaceIndex(pgm, 'txs', 'sponsor_address'); |
| 15 | + replaceIndex(pgm, 'txs', 'smart_contract_contract_id'); |
| 16 | + replaceIndex(pgm, 'txs', 'sender_address'); |
| 17 | + replaceIndex(pgm, 'txs', 'microblock_hash'); |
| 18 | + replaceIndex(pgm, 'txs', 'contract_call_contract_id'); |
| 19 | + |
| 20 | + replaceIndex(pgm, 'stx_events', 'tx_id'); |
| 21 | + replaceIndex(pgm, 'stx_events', 'sender'); |
| 22 | + replaceIndex(pgm, 'stx_events', 'recipient'); |
| 23 | + replaceIndex(pgm, 'stx_events', 'microblock_hash'); |
| 24 | + |
| 25 | + replaceIndex(pgm, 'miner_rewards', 'recipient'); |
| 26 | + |
| 27 | + pgm.dropIndex('stx_lock_events', 'block_height', { ifExists: true }); |
| 28 | + replaceIndex(pgm, 'stx_lock_events', 'tx_id'); |
| 29 | + replaceIndex(pgm, 'stx_lock_events', 'microblock_hash'); |
| 30 | + replaceIndex(pgm, 'stx_lock_events', 'locked_address'); |
| 31 | + |
| 32 | + replaceIndex(pgm, 'ft_events', 'tx_id'); |
| 33 | + replaceIndex(pgm, 'ft_events', 'sender'); |
| 34 | + replaceIndex(pgm, 'ft_events', 'recipient'); |
| 35 | + replaceIndex(pgm, 'ft_events', 'microblock_hash'); |
| 36 | + |
| 37 | + replaceIndex(pgm, 'nft_events', 'tx_id'); |
| 38 | + replaceIndex(pgm, 'nft_events', 'sender'); |
| 39 | + replaceIndex(pgm, 'nft_events', 'recipient'); |
| 40 | + replaceIndex(pgm, 'nft_events', 'microblock_hash'); |
| 41 | + replaceIndex(pgm, 'nft_events', 'asset_identifier'); |
| 42 | + |
| 43 | + replaceIndex(pgm, 'contract_logs', 'tx_id'); |
| 44 | + replaceIndex(pgm, 'contract_logs', 'microblock_hash'); |
| 45 | + |
| 46 | + replaceIndex(pgm, 'smart_contracts', 'contract_id'); |
| 47 | + replaceIndex(pgm, 'smart_contracts', 'microblock_hash'); |
| 48 | + |
| 49 | + pgm.dropIndex('principal_stx_txs', 'principal', { ifExists: true }); |
| 50 | + replaceIndex(pgm, 'principal_stx_txs', 'tx_id'); |
| 51 | + |
| 52 | + pgm.dropIndex('mempool_txs', 'tx_id', { ifExists: true }); |
| 53 | + replaceIndex(pgm, 'mempool_txs', 'token_transfer_recipient_address'); |
| 54 | + replaceIndex(pgm, 'mempool_txs', 'sponsor_address'); |
| 55 | + replaceIndex(pgm, 'mempool_txs', 'smart_contract_contract_id'); |
| 56 | + replaceIndex(pgm, 'mempool_txs', 'sender_address'); |
| 57 | + replaceIndex(pgm, 'mempool_txs', 'contract_call_contract_id'); |
| 58 | +}; |
| 59 | + |
| 60 | +exports.down = pgm => { |
| 61 | + pgm.createIndex('txs', [{ name: 'tx_index', sort: 'DESC' }]); |
| 62 | + pgm.createIndex('txs', 'tx_id', { method: 'hash' }); |
| 63 | + replaceIndex(pgm, 'txs', 'token_transfer_recipient_address', 'hash'); |
| 64 | + replaceIndex(pgm, 'txs', 'sponsor_address', 'hash'); |
| 65 | + replaceIndex(pgm, 'txs', 'smart_contract_contract_id', 'hash'); |
| 66 | + replaceIndex(pgm, 'txs', 'sender_address', 'hash'); |
| 67 | + replaceIndex(pgm, 'txs', 'microblock_hash', 'hash'); |
| 68 | + replaceIndex(pgm, 'txs', 'contract_call_contract_id', 'hash'); |
| 69 | + |
| 70 | + replaceIndex(pgm, 'stx_events', 'tx_id', 'hash'); |
| 71 | + replaceIndex(pgm, 'stx_events', 'sender', 'hash'); |
| 72 | + replaceIndex(pgm, 'stx_events', 'recipient', 'hash'); |
| 73 | + replaceIndex(pgm, 'stx_events', 'microblock_hash', 'hash'); |
| 74 | + |
| 75 | + replaceIndex(pgm, 'miner_rewards', 'recipient', 'hash'); |
| 76 | + |
| 77 | + pgm.createIndex('stx_lock_events', [{ name: 'block_height', sort: 'DESC' }]); |
| 78 | + replaceIndex(pgm, 'stx_lock_events', 'tx_id', 'hash'); |
| 79 | + replaceIndex(pgm, 'stx_lock_events', 'microblock_hash', 'hash'); |
| 80 | + replaceIndex(pgm, 'stx_lock_events', 'locked_address', 'hash'); |
| 81 | + |
| 82 | + replaceIndex(pgm, 'ft_events', 'tx_id', 'hash'); |
| 83 | + replaceIndex(pgm, 'ft_events', 'sender', 'hash'); |
| 84 | + replaceIndex(pgm, 'ft_events', 'recipient', 'hash'); |
| 85 | + replaceIndex(pgm, 'ft_events', 'microblock_hash', 'hash'); |
| 86 | + |
| 87 | + replaceIndex(pgm, 'nft_events', 'tx_id', 'hash'); |
| 88 | + replaceIndex(pgm, 'nft_events', 'sender', 'hash'); |
| 89 | + replaceIndex(pgm, 'nft_events', 'recipient', 'hash'); |
| 90 | + replaceIndex(pgm, 'nft_events', 'microblock_hash', 'hash'); |
| 91 | + replaceIndex(pgm, 'nft_events', 'asset_identifier', 'hash'); |
| 92 | + |
| 93 | + replaceIndex(pgm, 'contract_logs', 'tx_id', 'hash'); |
| 94 | + replaceIndex(pgm, 'contract_logs', 'microblock_hash', 'hash'); |
| 95 | + |
| 96 | + replaceIndex(pgm, 'smart_contracts', 'contract_id', 'hash'); |
| 97 | + replaceIndex(pgm, 'smart_contracts', 'microblock_hash', 'hash'); |
| 98 | + |
| 99 | + pgm.createIndex('principal_stx_txs', 'principal', { method: 'hash' }); |
| 100 | + replaceIndex(pgm, 'principal_stx_txs', 'tx_id', 'hash'); |
| 101 | + |
| 102 | + pgm.createIndex('mempool_txs', 'tx_id', { method: 'hash' }); |
| 103 | + replaceIndex(pgm, 'mempool_txs', 'token_transfer_recipient_address', 'hash'); |
| 104 | + replaceIndex(pgm, 'mempool_txs', 'sponsor_address', 'hash'); |
| 105 | + replaceIndex(pgm, 'mempool_txs', 'smart_contract_contract_id', 'hash'); |
| 106 | + replaceIndex(pgm, 'mempool_txs', 'sender_address', 'hash'); |
| 107 | + replaceIndex(pgm, 'mempool_txs', 'contract_call_contract_id', 'hash'); |
| 108 | +}; |
0 commit comments