aboutsummaryrefslogtreecommitdiffstats
path: root/packages/pipeline
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-11-15 10:39:06 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-12-05 06:24:48 +0800
commitb42cf0c797661bfc94eb8162817eb8fa118a69a2 (patch)
tree03259ba84bb2257fdb7ecf50c9184068539102eb /packages/pipeline
parent80763337953b4ac575cacdbcfdf79227229966e3 (diff)
downloaddexon-sol-tools-b42cf0c797661bfc94eb8162817eb8fa118a69a2.tar.gz
dexon-sol-tools-b42cf0c797661bfc94eb8162817eb8fa118a69a2.tar.zst
dexon-sol-tools-b42cf0c797661bfc94eb8162817eb8fa118a69a2.zip
Add workaround for broken save method
Diffstat (limited to 'packages/pipeline')
-rw-r--r--packages/pipeline/src/ormconfig.ts2
-rw-r--r--packages/pipeline/src/scripts/pull_missing_events.ts22
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.`);
}