|
3 | 3 | const _ = require('lodash'), |
4 | 4 | BbPromise = require('bluebird'), |
5 | 5 | tables = require('./tables/core'), |
| 6 | + dm = require('dynamodb-migrations'), |
| 7 | + AWS = require('aws-sdk'), |
6 | 8 | dynamodbLocal = require('dynamodb-localhost'); |
7 | 9 |
|
8 | 10 | module.exports = function(S) { // Always pass in the ServerlessPlugin Class |
@@ -125,16 +127,17 @@ module.exports = function(S) { // Always pass in the ServerlessPlugin Class |
125 | 127 | table = config && config.table || {}, |
126 | 128 | rootPath = S.getProject().getRootPath(), |
127 | 129 | 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) }, |
128 | 133 | suffix = table.suffix || '', |
129 | 134 | prefix = table.prefix || ''; |
130 | 135 |
|
| 136 | + dm.init(dynamodb, tablesPath); |
131 | 137 | if (options.new) { |
132 | | - tables.newTemplate(options.new, tablesPath).then(resolve, reject); |
| 138 | + dm.create(options.new).then(resolve, reject); |
133 | 139 | } 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); |
138 | 141 | } |
139 | 142 | }); |
140 | 143 | } |
|
0 commit comments