Skip to content

Commit bceaf1e

Browse files
committed
Tweaked automatic seeding and readme.
Changed merge order for proper use of cli-commands e.g. --seed.
1 parent f53b483 commit bceaf1e

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ dynamodb:
127127
> sls dynamodb start --seed=domain,test
128128
```
129129

130+
If seed config is set to true, your configuration will be seeded automatically on startup. You can also put the seed to false to prevent initial seeding to use manual seeding via cli.
131+
132+
```fake-test-users.json example
133+
[
134+
{
135+
"id": "John",
136+
"name": "Doe",
137+
},
138+
]
139+
```
140+
130141
## Using DynamoDB Local in your code
131142
You need to add the following parameters to the AWS NODE SDK dynamodb constructor
132143

index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ class ServerlessDynamodbLocal {
148148
const options = _.merge({
149149
sharedDb: this.options.sharedDb || true
150150
},
151-
this.options,
152-
config && config.start
151+
config && config.start,
152+
this.options
153153
);
154154

155155
dynamodbLocal.start(options);
@@ -181,12 +181,16 @@ class ServerlessDynamodbLocal {
181181
get seedSources() {
182182
const config = this.service.custom.dynamodb;
183183
const seedConfig = _.get(config, "seed", {});
184-
const seed = this.options.seed || Object.keys(seedConfig).join(',');
185-
if (!seed) {
186-
this.serverlessLog("DynamoDB - No seed categories defined. Skipping data seeding.");
184+
const seed = this.options.seed;
185+
let categories;
186+
if (typeof seed === "string") {
187+
categories = seed.split(",");
188+
} else if(seed) {
189+
categories = Object.keys(seedConfig);
190+
} else { // if (!seed)
191+
this.serverlessLog("DynamoDB - No seeding defined. Skipping data seeding.");
187192
return [];
188193
}
189-
const categories = seed.split(",");
190194
const sourcesByCategory = categories.map((category) => seedConfig[category].sources);
191195
return [].concat.apply([], sourcesByCategory);
192196
}

0 commit comments

Comments
 (0)