diff --git a/.gitignore b/.gitignore index fa5f753..21d6191 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules/ .DS_Store npdfile.js examples +.vscode/ diff --git a/README.md b/README.md index 8f5ff54..3819f96 100644 --- a/README.md +++ b/README.md @@ -434,7 +434,7 @@ module.exports = { development: { dynamoClient: dynamodb, migrations: { - ProvisionedThroughput: [10, 10], + // Omitting ProvisionedThroughput will default to on-demand tableName: 'npd_migrations' } }, @@ -481,6 +481,7 @@ exports.up = function(migrator){ t.string('room_id').hashKey(); t.number('user_id').rangeKey(); t.projectionTypeAll(); //default is NONE + // Not specifying `.provisionedThroughput` will default to on-demand }); }); }; diff --git a/lib/migrate/migrator.js b/lib/migrate/migrator.js index 89c8efd..a74cbd9 100644 --- a/lib/migrate/migrator.js +++ b/lib/migrate/migrator.js @@ -26,7 +26,10 @@ Migrator.prototype.createTable = function(tableName, callback){ var query = this.npd(); var builder = new SchemaBuilder({ apiVer: query.apiVersion, - tableName: tableName + tableName: tableName, + tableInfo: { + BillingMode: 'PAY_PER_REQUEST', + } }); callback(builder); @@ -117,7 +120,11 @@ MigrateRunner.prototype._createMigrateTableIfNotExits = function(){ return self.migrator().createTable(tableName, function(t){ t.number('version').hashKey(); - t.provisionedThroughput.apply(t, self.config.migrations.ProvisionedThroughput); + + // Will use default on-demand setup if no ProvisionedThroughput is defined + if (self.config.migrations.ProvisionedThroughput) { + t.provisionedThroughput.apply(t, self.config.migrations.ProvisionedThroughput); + } }) .then(function(){ return self.npd().rawClient().waitFor('tableExists', {TableName: tableName}); diff --git a/lib/schema/builder.js b/lib/schema/builder.js index 5c76465..e463d52 100644 --- a/lib/schema/builder.js +++ b/lib/schema/builder.js @@ -44,6 +44,11 @@ SchemaBuilder.prototype._definePropsIfNotExists = function(propName){ }; SchemaBuilder.prototype.provisionedThroughput = function(r, w){ + // Only set billing mode to 'PROVISIONED' if the propertiy was specified + if (this._schema.tableInfo.BillingMode) { + this._schema.tableInfo.BillingMode = 'PROVISIONED'; + } + this._definePropsIfNotExists('ProvisionedThroughput'); this._schema.tableInfo.ProvisionedThroughput.ReadCapacityUnits = r; this._schema.tableInfo.ProvisionedThroughput.WriteCapacityUnits = w; @@ -96,7 +101,10 @@ SchemaBuilder.prototype.globalSecondaryIndex = function(indexName, callback){ callback(this.__newBuilder({ IndexType: Schema.IndexType.GSI, tableInfo: { - IndexName: indexName + IndexName: indexName, + Projection: { + ProjectionType: 'NONE' + } } })); }; @@ -139,7 +147,10 @@ SchemaBuilder.prototype.localSecondaryIndex = function(indexName, callback){ var def = this.__newBuilder({ IndexType: Schema.IndexType.LSI, tableInfo: { - IndexName: indexName + IndexName: indexName, + Projection: { + ProjectionType: 'NONE' + } } }); @@ -181,14 +192,7 @@ function Schema(options){ this.IndexType = Schema.IndexType.DEFAULT; this.tableInfo = options.withoutDefaultTableInfo ? {} : { - IndexName: null, - ProvisionedThroughput: { - ReadCapacityUnits: 10, - WriteCapacityUnits: 10 - }, - Projection: { - ProjectionType: 'NONE' - } + IndexName: null }; this.mergeProps(options); diff --git a/test/data/test_tables.js b/test/data/test_tables.js index 50a9868..7a62874 100644 --- a/test/data/test_tables.js +++ b/test/data/test_tables.js @@ -12,6 +12,7 @@ exports.compex_table = { { AttributeName: 'range_key', KeyType: 'RANGE' } ], TableName: 'complex_table', + BillingMode: 'PROVISIONED', ProvisionedThroughput: { ReadCapacityUnits: 100, WriteCapacityUnits: 100 },