-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove obsolete nft_custody_unanchored table
- Loading branch information
Showing
5 changed files
with
140 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* eslint-disable camelcase */ | ||
|
||
exports.shorthands = undefined; | ||
|
||
exports.up = pgm => { | ||
pgm.dropTable('nft_custody_unanchored'); | ||
}; | ||
|
||
exports.down = pgm => { | ||
pgm.createTable('nft_custody_unanchored', { | ||
asset_identifier: { | ||
type: 'string', | ||
notNull: true, | ||
}, | ||
value: { | ||
type: 'bytea', | ||
notNull: true, | ||
}, | ||
recipient: { | ||
type: 'text', | ||
}, | ||
block_height: { | ||
type: 'integer', | ||
notNull: true, | ||
}, | ||
index_block_hash: { | ||
type: 'bytea', | ||
notNull: true, | ||
}, | ||
parent_index_block_hash: { | ||
type: 'bytea', | ||
notNull: true, | ||
}, | ||
microblock_hash: { | ||
type: 'bytea', | ||
notNull: true, | ||
}, | ||
microblock_sequence: { | ||
type: 'integer', | ||
notNull: true, | ||
}, | ||
tx_id: { | ||
type: 'bytea', | ||
notNull: true, | ||
}, | ||
tx_index: { | ||
type: 'smallint', | ||
notNull: true, | ||
}, | ||
event_index: { | ||
type: 'integer', | ||
notNull: true, | ||
}, | ||
}); | ||
pgm.createConstraint('nft_custody_unanchored', 'nft_custody_unanchored_unique', 'UNIQUE(asset_identifier, value)'); | ||
pgm.createIndex('nft_custody_unanchored', ['recipient', 'asset_identifier']); | ||
pgm.createIndex('nft_custody_unanchored', 'value'); | ||
pgm.createIndex('nft_custody_unanchored', [ | ||
{ name: 'block_height', sort: 'DESC' }, | ||
{ name: 'microblock_sequence', sort: 'DESC' }, | ||
{ name: 'tx_index', sort: 'DESC' }, | ||
{ name: 'event_index', sort: 'DESC' } | ||
]); | ||
pgm.sql(` | ||
INSERT INTO nft_custody_unanchored (asset_identifier, value, recipient, tx_id, block_height, index_block_hash, parent_index_block_hash, microblock_hash, microblock_sequence, tx_index, event_index) ( | ||
SELECT | ||
DISTINCT ON(asset_identifier, value) asset_identifier, value, recipient, tx_id, nft.block_height, | ||
nft.index_block_hash, nft.parent_index_block_hash, nft.microblock_hash, nft.microblock_sequence, nft.tx_index, nft.event_index | ||
FROM | ||
nft_events AS nft | ||
INNER JOIN | ||
txs USING (tx_id) | ||
WHERE | ||
txs.canonical = true | ||
AND txs.microblock_canonical = true | ||
AND nft.canonical = true | ||
AND nft.microblock_canonical = true | ||
ORDER BY | ||
asset_identifier, | ||
value, | ||
txs.block_height DESC, | ||
txs.microblock_sequence DESC, | ||
txs.tx_index DESC, | ||
nft.event_index DESC | ||
) | ||
`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters