@@ -15,11 +15,11 @@ const MIGRATION_SEED_CONCURRENCY = 5;
1515/**
1616 * Writes a batch chunk of migration seeds to DynamoDB. DynamoDB has a limit on the number of
1717 * items that may be written in a batch operation.
18- * @param {DynamoDocumentClient } dynamodb The DynamoDB Document client
18+ * @param {function } dynamodbWriteFunction The DynamoDB DocumentClient.batchWrite or DynamoDB.batchWriteItem function
1919 * @param {string } tableName The table name being written to
2020 * @param {any[] } seeds The migration seeds being written to the table
2121 */
22- function writeSeedBatch ( dynamodb , tableName , seeds ) {
22+ function writeSeedBatch ( dynamodbWriteFunction , tableName , seeds ) {
2323 const params = {
2424 RequestItems : {
2525 [ tableName ] : seeds . map ( ( seed ) => ( {
@@ -34,7 +34,7 @@ function writeSeedBatch(dynamodb, tableName, seeds) {
3434 // again a few times in case the Database resources are in the middle of provisioning.
3535 let interval = 0 ;
3636 function execute ( interval ) {
37- setTimeout ( ( ) => dynamodb . batchWrite ( params , ( err ) => {
37+ setTimeout ( ( ) => dynamodbWriteFunction ( params , ( err ) => {
3838 if ( err ) {
3939 if ( err . code === "ResourceNotFoundException" && interval <= 5000 ) {
4040 execute ( interval + 1000 ) ;
@@ -52,13 +52,13 @@ function writeSeedBatch(dynamodb, tableName, seeds) {
5252
5353/**
5454 * Writes a seed corpus to the given database table
55- * @param {DocumentClient } dynamodb The DynamoDB document instance
55+ * @param {function } dynamodbWriteFunction The DynamoDB DocumentClient.batchWrite or DynamoDB.batchWriteItem function
5656 * @param {string } tableName The table name
5757 * @param {any[] } seeds The seed values
5858 */
59- function writeSeeds ( dynamodb , tableName , seeds ) {
60- if ( ! dynamodb ) {
61- throw new Error ( "dynamodb argument must be provided" ) ;
59+ function writeSeeds ( dynamodbWriteFunction , tableName , seeds ) {
60+ if ( ! dynamodbWriteFunction ) {
61+ throw new Error ( "dynamodbWriteFunction argument must be provided" ) ;
6262 }
6363 if ( ! tableName ) {
6464 throw new Error ( "table name argument must be provided" ) ;
@@ -71,7 +71,7 @@ function writeSeeds(dynamodb, tableName, seeds) {
7171 const seedChunks = _ . chunk ( seeds , MAX_MIGRATION_CHUNK ) ;
7272 return BbPromise . map (
7373 seedChunks ,
74- ( chunk ) => writeSeedBatch ( dynamodb , tableName , chunk ) ,
74+ ( chunk ) => writeSeedBatch ( dynamodbWriteFunction , tableName , chunk ) ,
7575 { concurrency : MIGRATION_SEED_CONCURRENCY }
7676 )
7777 . then ( ( ) => console . log ( "Seed running complete for table: " + tableName ) ) ;
0 commit comments