Skip to content

Commit

Permalink
Improve seeding logging (#42)
Browse files Browse the repository at this point in the history
This avoids logging twice for each table, and avoids misleading logs that suggest seeding is complete for a table when it is not.
  • Loading branch information
domdomegg authored Feb 13, 2024
1 parent d19168d commit 6a16b74
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);

Check warning on line 261 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci (lts/*)

Unexpected console statement

Check warning on line 261 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci (current)

Unexpected console statement
}));
return;
}
Expand Down
3 changes: 1 addition & 2 deletions src/seeder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <T>(input: T[], size: number): T[][] => {
Expand Down

0 comments on commit 6a16b74

Please sign in to comment.