Skip to content

Commit 6de54d4

Browse files
Merge pull request #44 from gwincr11/cg-table-migration-options
allow prefix and suffix to be passed in
2 parents 4857d1c + 522c262 commit 6de54d4

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

index.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,16 @@ module.exports = function (S) {
5252
option: 'stage',
5353
shortcut: 's',
5454
description: 'Stage that dynamodb should be remotely executed'
55-
}]
55+
}, {
56+
option: 'table_prefix',
57+
shortcut: 'p',
58+
description: 'Table name prefix'
59+
}, {
60+
option: 'table_suffix',
61+
shortcut: 'x',
62+
description: 'Table name suffix'
63+
}
64+
]
5665
});
5766
S.addAction(this.executeAll.bind(this), {
5867
handler: 'dynamodbExecuteAll',
@@ -67,6 +76,14 @@ module.exports = function (S) {
6776
option: 'stage',
6877
shortcut: 's',
6978
description: 'Stage that dynamodb should be remotely executed'
79+
}, {
80+
option: 'table_prefix',
81+
shortcut: 'p',
82+
description: 'Table name prefix'
83+
}, {
84+
option: 'table_suffix',
85+
shortcut: 'x',
86+
description: 'Table name suffix'
7087
}]
7188
});
7289
S.addAction(this.remove.bind(this), {
@@ -149,13 +166,13 @@ module.exports = function (S) {
149166
};
150167
}
151168

152-
tableOptions() {
169+
tableOptions(table_prefix, table_suffix) {
153170
let config = S.getProject().custom.dynamodb,
154171
migration = config && config.migration || {},
155172
rootPath = S.getProject().getRootPath(),
156173
path = rootPath + '/' + (migration.dir || 'dynamodb'),
157-
suffix = migration.table_suffix || '',
158-
prefix = migration.table_prefix || '';
174+
suffix = table_suffix || migration.table_suffix || '',
175+
prefix = table_prefix || migration.table_prefix || '';
159176

160177
return {
161178
suffix: suffix,
@@ -189,7 +206,7 @@ module.exports = function (S) {
189206
options = evt.options;
190207
return new BbPromise(function (resolve, reject) {
191208
let dynamodb = self.dynamodbOptions(options.stage, options.region),
192-
tableOptions = self.tableOptions();
209+
tableOptions = self.tableOptions(options.table_prefix, options.table_suffix);
193210
dynamodbMigrations.init(dynamodb, tableOptions.path);
194211
dynamodbMigrations.execute(options.name, tableOptions).then(resolve, reject);
195212
});
@@ -200,7 +217,7 @@ module.exports = function (S) {
200217
options = evt.options;
201218
return new BbPromise(function (resolve, reject) {
202219
let dynamodb = self.dynamodbOptions(options.stage, options.region),
203-
tableOptions = self.tableOptions();
220+
tableOptions = self.tableOptions(options.table_prefix, options.table_suffix);
204221
dynamodbMigrations.init(dynamodb, tableOptions.path);
205222
dynamodbMigrations.executeAll(tableOptions).then(resolve, reject);
206223
});

0 commit comments

Comments
 (0)