Skip to content

Commit

Permalink
createMigrateTableIfNotExists now works when there are more than 100 …
Browse files Browse the repository at this point in the history
…tables
  • Loading branch information
sean-krail committed Dec 4, 2019
1 parent b876981 commit 6e087ca
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions lib/migrate/migrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,28 @@ function MigrateRunner(config){
this.migrator = create(npd);
}

MigrateRunner.prototype._createMigrateTableIfNotExits = function(){
MigrateRunner.prototype._createMigrateTableIfNotExists = function() {
var self = this;
var tableName = this.config.migrations.tableName;
return this.npd().showTables()
.then(function(tables){
var isFound = _.find(tables.TableNames, function(t){ return t === tableName });
if(isFound) { return; }

return self.migrator().createTable(tableName, function(t){
t.number('version').hashKey();
t.provisionedThroughput.apply(t, self.config.migrations.ProvisionedThroughput);
})
.then(function(){
return self.npd().rawClient().waitFor('tableExists', {TableName: tableName});
return new Promise(function(resolve, reject) {
self.npd().table(tableName).describe().then(function(_) {
resolve();
}).catch(function (err) {
if (!err) {
reject();
} else if (err.code === 'ResourceInUseException') {
resolve();
} else if (err.code === 'ResourceNotFoundException') {
self.migrator().createTable(tableName, function(t) {
t.number('version').hashKey();
t.provisionedThroughput.apply(t, self.config.migrations.ProvisionedThroughput);
})
.then(function() {
self.npd().rawClient().waitFor('tableExists', {TableName: tableName}).then(resolve).catch(reject);
}).catch(reject);
} else {
reject();
}
});
});
};
Expand All @@ -129,7 +137,7 @@ MigrateRunner.prototype.run = function(){
var self = this;
var tableName = this.config.migrations.tableName;

return this._createMigrateTableIfNotExits().then(function(){
return this._createMigrateTableIfNotExists().then(function(){
return self.npd().table(tableName).all().then(function(data){
var dirs = fs.readdirSync(self.config.cwd);

Expand Down Expand Up @@ -165,6 +173,8 @@ MigrateRunner.prototype.run = function(){

return utils.PromiseWaterfall(tasks);
});
}).catch(function (err) {
console.error(err);
});
};

Expand Down

0 comments on commit 6e087ca

Please sign in to comment.