diff options
author | Alex Browne <stephenalexbrowne@gmail.com> | 2018-11-15 10:39:06 +0800 |
---|---|---|
committer | Fred Carlsen <fred@sjelfull.no> | 2018-12-06 19:04:25 +0800 |
commit | 6bab2f70b956653367b046f4688d789f81de0b85 (patch) | |
tree | 84c44045650989332a48d73c4b83f654d8f9f11b | |
parent | a0a41b1b5d4f9bcaf4fd15ccf628e7e6b88b4621 (diff) | |
download | dexon-sol-tools-6bab2f70b956653367b046f4688d789f81de0b85.tar dexon-sol-tools-6bab2f70b956653367b046f4688d789f81de0b85.tar.gz dexon-sol-tools-6bab2f70b956653367b046f4688d789f81de0b85.tar.bz2 dexon-sol-tools-6bab2f70b956653367b046f4688d789f81de0b85.tar.lz dexon-sol-tools-6bab2f70b956653367b046f4688d789f81de0b85.tar.xz dexon-sol-tools-6bab2f70b956653367b046f4688d789f81de0b85.tar.zst dexon-sol-tools-6bab2f70b956653367b046f4688d789f81de0b85.zip |
Add workaround for broken save method
-rw-r--r-- | packages/pipeline/src/ormconfig.ts | 2 | ||||
-rw-r--r-- | packages/pipeline/src/scripts/pull_missing_events.ts | 22 |
2 files changed, 22 insertions, 2 deletions
diff --git a/packages/pipeline/src/ormconfig.ts b/packages/pipeline/src/ormconfig.ts index 0e489e560..64b5b1827 100644 --- a/packages/pipeline/src/ormconfig.ts +++ b/packages/pipeline/src/ormconfig.ts @@ -26,7 +26,7 @@ const config: ConnectionOptions = { type: 'postgres', url: process.env.ZEROEX_DATA_PIPELINE_DB_URL, synchronize: false, - logging: ['error', 'warn'], + // logging: ['error'], entities, migrations: ['./lib/migrations/**/*.js'], }; diff --git a/packages/pipeline/src/scripts/pull_missing_events.ts b/packages/pipeline/src/scripts/pull_missing_events.ts index f53bc12bd..2dc81f205 100644 --- a/packages/pipeline/src/scripts/pull_missing_events.ts +++ b/packages/pipeline/src/scripts/pull_missing_events.ts @@ -38,7 +38,27 @@ async function getExchangeEventsAsync(provider: Web3ProviderEngine): Promise<voi const events = parseExchangeEvents(eventLogs); console.log(`Retrieved and parsed ${events.length} total events.`); console.log('Saving events...'); - await eventsRepository.save(events, { chunk: Math.ceil(events.length / BATCH_SAVE_SIZE) }); + // Note(albrow): This is a temporary hack because `save` is not working as + // documented and is causing a foreign key constraint violation. Hopefully + // can remove later because this "poor man's upsert" implementation operates + // on one event at a time and is therefore much slower. + // await eventsRepository.save(events, { chunk: Math.ceil(events.length / BATCH_SAVE_SIZE) }); + for (const event of events) { + try { + await eventsRepository.save(event); + } catch { + // Assume this is a foreign key constraint error and try doing an + // update instead. + await eventsRepository.update( + { + contractAddress: event.contractAddress, + blockNumber: event.blockNumber, + logIndex: event.logIndex, + }, + event, + ); + } + } const totalEvents = await eventsRepository.count(); console.log(`Done saving events. There are now ${totalEvents} total events.`); } |