-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create tx id column in smart contract event (main) (#651) TG-16…
…6 #waiting * feat: create tx_id column in smart_contract_event * fix: update query smart_contract_event join event only; remove knex.transaction * feat: add tx_id to smart_contract_event in hasura metadata
- Loading branch information
1 parent
3257cac
commit 557a79f
Showing
6 changed files
with
55 additions
and
4 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
45 changes: 45 additions & 0 deletions
45
migrations/20240110032646_create_tx_id_column_in_smart_contract_event.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,45 @@ | ||
import { Knex } from 'knex'; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
console.log('create tx_id column in smart_contract_event'); | ||
const chunkSizeQuery = 10000; | ||
let startId = 0; | ||
|
||
await knex.schema.alterTable('smart_contract_event', (table) => { | ||
table.integer('tx_id').index(); | ||
}); | ||
let done = false; | ||
while (!done) { | ||
console.log(`update tx_id column in smart_contract_event at id ${startId}`); | ||
const smartContractEvents = await knex.raw( | ||
`select smart_contract_event.id smart_contract_event_id, | ||
event.tx_id transaction_id from smart_contract_event | ||
join event on event.id = smart_contract_event.event_id | ||
where smart_contract_event.id > ${startId} | ||
order by smart_contract_event.id asc | ||
limit ${chunkSizeQuery};` | ||
); | ||
if (smartContractEvents.rows.length === 0) { | ||
done = true; | ||
break; | ||
} | ||
const stringListUpdates = smartContractEvents.rows | ||
.map( | ||
(update: any) => | ||
`(${update.smart_contract_event_id}, ${update.transaction_id})` | ||
) | ||
.join(','); | ||
await knex.raw( | ||
`UPDATE smart_contract_event SET tx_id = temp.tx_id from (VALUES ${stringListUpdates}) as temp(id, tx_id) where temp.id = smart_contract_event.id` | ||
); | ||
startId = | ||
smartContractEvents.rows[smartContractEvents.rows.length - 1] | ||
.smart_contract_event_id; | ||
} | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
await knex.schema.alterTable('smart_contract_event', (table) => { | ||
table.dropColumn('tx_id'); | ||
}); | ||
} |
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