Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating "Pay per request" as default BillingMode unless otherwise specified #70

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules/
.DS_Store
npdfile.js
examples
.vscode/
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ module.exports = {
development: {
dynamoClient: dynamodb,
migrations: {
ProvisionedThroughput: [10, 10],
// Omitting ProvisionedThroughput will default to on-demand
tableName: 'npd_migrations'
}
},
Expand Down Expand Up @@ -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
});
});
};
Expand Down
11 changes: 9 additions & 2 deletions lib/migrate/migrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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});
Expand Down
24 changes: 14 additions & 10 deletions lib/schema/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'
}
}
}));
};
Expand Down Expand Up @@ -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'
}
}
});

Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions test/data/test_tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exports.compex_table = {
{ AttributeName: 'range_key', KeyType: 'RANGE' }
],
TableName: 'complex_table',
BillingMode: 'PROVISIONED',
ProvisionedThroughput: {
ReadCapacityUnits: 100, WriteCapacityUnits: 100
},
Expand Down