From 8176c8c739320e44cbae4217b55f311570590b2a Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Tue, 13 Feb 2024 21:50:26 +0000 Subject: [PATCH] Improve seeding logging This avoids logging twice for each table, and avoids misleading logs that suggest seeding is complete for a table when it is not. --- src/index.ts | 5 +++-- src/seeder.ts | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index e1853cd..91b57c9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -251,13 +251,14 @@ class ServerlessDynamoDBPlugin implements Plugin { if (this.shouldExecute()) { const dynamodb = this.dynamodbOptions(); - await Promise.all(this.seedSources.flatMap(async (source) => { + await Promise.all(this.seedSources.map(async (source) => { if (!source.table) { throw new Error('seeding source "table" property not defined'); } const seedPromise = writeSeeds((params) => dynamodb.doc.send(new BatchWriteCommand(params)), source.table, locateSeeds(source.sources || [])); const rawSeedPromise = writeSeeds((params) => dynamodb.raw.send(new BatchWriteItemCommand(params)), source.table, locateSeeds(source.rawsources || [])); - return [seedPromise, rawSeedPromise]; + await Promise.all([seedPromise, rawSeedPromise]); + console.log(`Seed running complete for table: ${source.table}`); })); return; } diff --git a/src/seeder.ts b/src/seeder.ts index 0c088a6..f1e36d2 100644 --- a/src/seeder.ts +++ b/src/seeder.ts @@ -66,8 +66,7 @@ export async function writeSeeds(dynamodbWriteFunction: DynamoDBWriteFunction, t } const seedChunks = chunk(seedValues, MAX_MIGRATION_CHUNK); - await Promise.all(seedChunks.map((chunk) => writeSeedBatch(dynamodbWriteFunction, tableName, chunk))) - .then(() => console.log(`Seed running complete for table: ${tableName}`)); + await Promise.all(seedChunks.map((chunk) => writeSeedBatch(dynamodbWriteFunction, tableName, chunk))); } const chunk = (input: T[], size: number): T[][] => {