Skip to content

Commit 76a01e7

Browse files
committed
Replace dynamodb migration handling functionality with dynamodb-migrations library #27
1 parent 1ec0467 commit 76a01e7

File tree

4 files changed

+9
-150
lines changed

4 files changed

+9
-150
lines changed

index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
const _ = require('lodash'),
44
BbPromise = require('bluebird'),
55
tables = require('./tables/core'),
6+
dm = require('dynamodb-migrations'),
7+
AWS = require('aws-sdk'),
68
dynamodbLocal = require('dynamodb-localhost');
79

810
module.exports = function(S) { // Always pass in the ServerlessPlugin Class
@@ -125,16 +127,17 @@ module.exports = function(S) { // Always pass in the ServerlessPlugin Class
125127
table = config && config.table || {},
126128
rootPath = S.getProject().getRootPath(),
127129
tablesPath = rootPath + '/' + (table.dir || 'dynamodb'),
130+
dbPort = config && config.start && config.start.port || 8000,
131+
dbOptions = { region: 'localhost', endpoint: 'http://localhost:' + dbPort },
132+
dynamodb = { raw: new AWS.DynamoDB(dbOptions), doc: new AWS.DynamoDB.DocumentClient(dbOptions) },
128133
suffix = table.suffix || '',
129134
prefix = table.prefix || '';
130135

136+
dm.init(dynamodb, tablesPath);
131137
if (options.new) {
132-
tables.newTemplate(options.new, tablesPath).then(resolve, reject);
138+
dm.create(options.new).then(resolve, reject);
133139
} else if (options.create) {
134-
tables.create(tablesPath, {
135-
prefix: prefix,
136-
suffix: suffix
137-
}).then(resolve, reject);
140+
dm.executeAll({ tablePrefix: prefix, tableSuffix: suffix }).then(resolve, reject);
138141
}
139142
});
140143
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"aws-sdk": "^2.3.19",
4040
"bluebird": "^3.0.6",
4141
"dynamodb-localhost": "0.0.2",
42+
"dynamodb-migrations": "0.0.3",
4243
"lodash": "^4.13.1",
4344
"mkdirp": "^0.5.0",
4445
"tar": "^2.0.0"

tables/core.js

Lines changed: 0 additions & 86 deletions
This file was deleted.

tables/templates/table.json

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)