|
| 1 | +// @ts-check |
| 2 | +/** @param { import("node-pg-migrate").MigrationBuilder } pgm */ |
| 3 | +exports.up = pgm => { |
| 4 | + /** |
| 5 | + * A previous migration used `order` instead of `sort` in the index definition which caused it to be ignored and default to ASC. |
| 6 | + * The `@ts-check` directive at the top of the file will catch these errors in the future. |
| 7 | + */ |
| 8 | + |
| 9 | + pgm.dropIndex('principal_stx_txs', [], { name: 'idx_principal_stx_txs_optimized' }); |
| 10 | + pgm.dropIndex('ft_events', [], { name: 'idx_ft_events_optimized' }); |
| 11 | + pgm.dropIndex('nft_events', [], { name: 'idx_nft_events_optimized' }); |
| 12 | + pgm.dropIndex('mempool_txs', [], { name: 'idx_mempool_txs_optimized' }); |
| 13 | + |
| 14 | + pgm.createIndex( |
| 15 | + 'principal_stx_txs', |
| 16 | + [ |
| 17 | + 'principal', |
| 18 | + { name: 'block_height', sort: 'DESC' }, |
| 19 | + { name: 'microblock_sequence', sort: 'DESC' }, |
| 20 | + { name: 'tx_index', sort: 'DESC' }], |
| 21 | + { |
| 22 | + name: 'idx_principal_stx_txs_optimized', |
| 23 | + where: 'canonical = TRUE AND microblock_canonical = TRUE', |
| 24 | + } |
| 25 | + ); |
| 26 | + |
| 27 | + pgm.createIndex( |
| 28 | + 'nft_events', |
| 29 | + [ |
| 30 | + 'sender', |
| 31 | + 'recipient', |
| 32 | + { name: 'block_height', sort: 'DESC' }, |
| 33 | + { name: 'microblock_sequence', sort: 'DESC' }, |
| 34 | + { name: 'tx_index', sort: 'DESC' }, |
| 35 | + { name: 'event_index', sort: 'DESC' } |
| 36 | + ], |
| 37 | + { |
| 38 | + name: 'idx_nft_events_optimized', |
| 39 | + where: 'canonical = TRUE AND microblock_canonical = TRUE', |
| 40 | + } |
| 41 | + ); |
| 42 | + |
| 43 | + pgm.createIndex( |
| 44 | + 'ft_events', |
| 45 | + [ |
| 46 | + 'sender', |
| 47 | + { name: 'block_height', sort: 'DESC' }, |
| 48 | + { name: 'microblock_sequence', sort: 'DESC' }, |
| 49 | + { name: 'tx_index', sort: 'DESC' }, |
| 50 | + { name: 'event_index', sort: 'DESC' } |
| 51 | + ], |
| 52 | + { |
| 53 | + name: 'idx_ft_events_optimized_sender', |
| 54 | + where: 'canonical = TRUE AND microblock_canonical = TRUE', |
| 55 | + } |
| 56 | + ); |
| 57 | + |
| 58 | + pgm.createIndex( |
| 59 | + 'ft_events', |
| 60 | + [ |
| 61 | + 'recipient', |
| 62 | + { name: 'block_height', sort: 'DESC' }, |
| 63 | + { name: 'microblock_sequence', sort: 'DESC' }, |
| 64 | + { name: 'tx_index', sort: 'DESC' }, |
| 65 | + { name: 'event_index', sort: 'DESC' } |
| 66 | + ], |
| 67 | + { |
| 68 | + name: 'idx_ft_events_optimized_recipient', |
| 69 | + where: 'canonical = TRUE AND microblock_canonical = TRUE', |
| 70 | + } |
| 71 | + ); |
| 72 | + |
| 73 | + pgm.createIndex( |
| 74 | + 'mempool_txs', |
| 75 | + [ |
| 76 | + { name: 'receipt_time', sort: 'DESC' } |
| 77 | + ], |
| 78 | + { |
| 79 | + name: 'idx_mempool_txs_optimized', |
| 80 | + where: 'pruned = FALSE', |
| 81 | + } |
| 82 | + ); |
| 83 | + |
| 84 | +}; |
| 85 | + |
| 86 | +/** @param { import("node-pg-migrate").MigrationBuilder } pgm */ |
| 87 | +exports.down = pgm => { |
| 88 | + pgm.dropIndex('principal_stx_txs', [], { name: 'idx_principal_stx_txs_optimized' }); |
| 89 | + pgm.dropIndex('ft_events', [], { name: 'idx_ft_events_optimized_sender' }); |
| 90 | + pgm.dropIndex('ft_events', [], { name: 'idx_ft_events_optimized_recipient' }); |
| 91 | + pgm.dropIndex('nft_events', [], { name: 'idx_nft_events_optimized' }); |
| 92 | + pgm.dropIndex('mempool_txs', [], { name: 'idx_mempool_txs_optimized' }); |
| 93 | + |
| 94 | + pgm.createIndex( |
| 95 | + 'principal_stx_txs', |
| 96 | + [ |
| 97 | + 'principal', |
| 98 | + // @ts-ignore |
| 99 | + { name: 'block_height', order: 'DESC' }, |
| 100 | + // @ts-ignore |
| 101 | + { name: 'microblock_sequence', order: 'DESC' }, |
| 102 | + // @ts-ignore |
| 103 | + { name: 'tx_index', order: 'DESC' }], |
| 104 | + { |
| 105 | + name: 'idx_principal_stx_txs_optimized', |
| 106 | + where: 'canonical = TRUE AND microblock_canonical = TRUE', |
| 107 | + } |
| 108 | + ); |
| 109 | + |
| 110 | + pgm.createIndex( |
| 111 | + 'ft_events', |
| 112 | + [ |
| 113 | + 'sender', |
| 114 | + 'recipient', |
| 115 | + // @ts-ignore |
| 116 | + { name: 'block_height', order: 'DESC' }, |
| 117 | + // @ts-ignore |
| 118 | + { name: 'microblock_sequence', order: 'DESC' }, |
| 119 | + // @ts-ignore |
| 120 | + { name: 'tx_index', order: 'DESC' }, |
| 121 | + // @ts-ignore |
| 122 | + { name: 'event_index', order: 'DESC' } |
| 123 | + ], |
| 124 | + { |
| 125 | + name: 'idx_ft_events_optimized', |
| 126 | + where: 'canonical = TRUE AND microblock_canonical = TRUE', |
| 127 | + } |
| 128 | + ); |
| 129 | + |
| 130 | + pgm.createIndex( |
| 131 | + 'nft_events', |
| 132 | + [ |
| 133 | + 'sender', |
| 134 | + 'recipient', |
| 135 | + // @ts-ignore |
| 136 | + { name: 'block_height', order: 'DESC' }, |
| 137 | + // @ts-ignore |
| 138 | + { name: 'microblock_sequence', order: 'DESC' }, |
| 139 | + // @ts-ignore |
| 140 | + { name: 'tx_index', order: 'DESC' }, |
| 141 | + // @ts-ignore |
| 142 | + { name: 'event_index', order: 'DESC' } |
| 143 | + ], |
| 144 | + { |
| 145 | + name: 'idx_nft_events_optimized', |
| 146 | + where: 'canonical = TRUE AND microblock_canonical = TRUE', |
| 147 | + } |
| 148 | + ); |
| 149 | + |
| 150 | + pgm.createIndex( |
| 151 | + 'mempool_txs', |
| 152 | + [ |
| 153 | + 'sender_address', |
| 154 | + 'sponsor_address', |
| 155 | + 'token_transfer_recipient_address', |
| 156 | + // @ts-ignore |
| 157 | + { name: 'receipt_time', order: 'DESC' } |
| 158 | + ], |
| 159 | + { |
| 160 | + name: 'idx_mempool_txs_optimized', |
| 161 | + where: 'pruned = FALSE', |
| 162 | + } |
| 163 | + ); |
| 164 | +}; |
0 commit comments