-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eebe700
commit 1a394f4
Showing
5 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
migrations/evm/20240916032201_erc721_contract_totalSupply.ts
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,30 @@ | ||
import { Knex } from 'knex'; | ||
import { Erc721Token } from '../../src/models'; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
await knex.schema.alterTable('erc721_contract', (table) => { | ||
table.integer('total_supply').defaultTo(0).index(); | ||
}); | ||
await knex.raw(`set statement_timeout to 0`); | ||
const totalSupplies = await Erc721Token.query(knex) | ||
.select('erc721_token.erc721_contract_address') | ||
.count() | ||
.groupBy('erc721_token.erc721_contract_address'); | ||
if (totalSupplies.length > 0) { | ||
const stringListUpdates = totalSupplies | ||
.map( | ||
(totalSuply) => | ||
`('${totalSuply.erc721_contract_address}', ${totalSuply.count})` | ||
) | ||
.join(','); | ||
await knex.raw( | ||
`UPDATE erc721_contract SET total_supply = temp.total_supply from (VALUES ${stringListUpdates}) as temp(address, total_supply) where temp.address = erc721_contract.address` | ||
); | ||
} | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
await knex.schema.alterTable('erc721_contract', (table) => { | ||
table.dropColumn('total_supply'); | ||
}); | ||
} |
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