Skip to content

chore: consolidate db migrations #1314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/migrations/1591291822107_mempool_txs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ export async function up(pgm: MigrationBuilder): Promise<void> {

// `coinbase` tx types
coinbase_payload: 'bytea',
tx_size: {
type: 'integer',
notNull: true,
expressionGenerated: 'length(raw_tx)'
}
});

pgm.createIndex('mempool_txs', 'tx_id', { method: 'hash' });
Expand All @@ -100,6 +105,9 @@ export async function up(pgm: MigrationBuilder): Promise<void> {
pgm.createIndex('mempool_txs', 'sponsor_address', { method: 'hash' });
pgm.createIndex('mempool_txs', 'token_transfer_recipient_address', { method: 'hash' });
pgm.createIndex('mempool_txs', [{ name: 'receipt_time', sort: 'DESC' }]);
pgm.createIndex('mempool_txs', ['type_id', 'receipt_block_height'], { where: 'pruned = false'});
pgm.createIndex('mempool_txs', ['type_id', 'fee_rate'], { where: 'pruned = false'});
pgm.createIndex('mempool_txs', ['type_id', 'tx_size'], { where: 'pruned = false'});

pgm.addConstraint('mempool_txs', 'unique_tx_id', `UNIQUE(tx_id)`);

Expand Down
5 changes: 5 additions & 0 deletions src/migrations/1621511823100_token_metadata_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export async function up(pgm: MigrationBuilder): Promise<void> {
processed: {
type: 'boolean',
notNull: true,
},
retry_count: {
type: 'integer',
notNull: true,
default: 0,
}
});

Expand Down
3 changes: 2 additions & 1 deletion src/migrations/1636130197558_nft_custody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export async function up(pgm: MigrationBuilder): Promise<void> {
`);

pgm.createIndex('nft_custody', ['recipient', 'asset_identifier']);
pgm.createIndex('nft_custody', 'asset_identifier');
pgm.createIndex('nft_custody', ['asset_identifier', 'value'], { unique: true });
pgm.createIndex('nft_custody', 'value');
}
3 changes: 2 additions & 1 deletion src/migrations/1640037852136_nft_custody_unanchored.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ export async function up(pgm: MigrationBuilder): Promise<void> {
`);

pgm.createIndex('nft_custody_unanchored', ['recipient', 'asset_identifier']);
pgm.createIndex('nft_custody_unanchored', 'asset_identifier');
pgm.createIndex('nft_custody_unanchored', ['asset_identifier', 'value'], { unique: true });
pgm.createIndex('nft_custody_unanchored', 'value');
}
3 changes: 3 additions & 0 deletions src/migrations/1643755236533_chain_tip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ export async function up(pgm: MigrationBuilder): Promise<void> {
LEFT JOIN microblock_count ON TRUE
LEFT JOIN tx_count ON TRUE
LEFT JOIN tx_count_unanchored ON TRUE
LIMIT 1
`);

pgm.createIndex('chain_tip', 'block_height', { unique: true });
}
3 changes: 3 additions & 0 deletions src/migrations/1647573802137_mempool_digest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ export async function up(pgm: MigrationBuilder): Promise<void> {
// extension which might not be possible for some users.
pgm.createMaterializedView('mempool_digest', {}, `SELECT NULL AS digest`);
}

pgm.createIndex('mempool_digest', 'digest', { unique: true });
}

export async function down(pgm: MigrationBuilder): Promise<void> {
pgm.dropIndex('mempool_digest', 'digest', { unique: true, ifExists: true });
pgm.dropMaterializedView('mempool_digest');
}
14 changes: 0 additions & 14 deletions src/migrations/1652304516306_token_metadata_queue_retry_count.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/migrations/1655235863682_nft_custody_value_index.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/migrations/1659435823368_mempool_indexes.ts

This file was deleted.

98 changes: 0 additions & 98 deletions src/migrations/1660595195398_materialized_view_indexes.ts

This file was deleted.