Files
stacks-blockchain-api/migrations/1702913457527_block-tx-count.js
Rafael Cárdenas da4cd569a5 feat: add tx_count property to /extended/v2/blocks (#1778)
* fix: move to tx_count

* docs: add new transactions endpoint docs

* fix: unused exports

* feat: transactions per block

* test: 404 on block
2023-12-19 10:02:02 -06:00

27 lines
540 B
JavaScript

/* eslint-disable camelcase */
exports.shorthands = undefined;
exports.up = pgm => {
pgm.addColumns('blocks', {
tx_count: {
type: 'int',
default: 1,
},
});
pgm.sql(`
UPDATE blocks SET tx_count = (
SELECT COUNT(*)::int
FROM txs
WHERE index_block_hash = blocks.index_block_hash
AND canonical = TRUE
AND microblock_canonical = TRUE
)
`);
pgm.alterColumn('blocks', 'tx_count', { notNull: true });
};
exports.down = pgm => {
pgm.dropColumn('blocks', ['tx_count']);
};