Skip to content

Commit

Permalink
Improvements to initial data creation
Browse files Browse the repository at this point in the history
  • Loading branch information
JedWatson committed May 20, 2019
1 parent d5d7207 commit 086e582
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions demo-projects/meetup/initialData.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ require('dotenv').config();

// Lets not hardcode password, even for test data
const password = process.env.INITIAL_DATA_PASSWORD;
const PASSWORD_MIN_LENGTH = 8;

if (!password) {
throw new Error(`To seed initial data, set the 'INITIAL_DATA_PASSWORD' environment variable`);
} else if (password.length < 10) {
} else if (password.length < PASSWORD_MIN_LENGTH) {
throw new Error(
`To seed initial data, the 'INITIAL_DATA_PASSWORD' must be at least 10 characters`
`To seed initial data, the 'INITIAL_DATA_PASSWORD' environment variable must be at least ${PASSWORD_MIN_LENGTH} characters`
);
}

Expand Down
2 changes: 1 addition & 1 deletion demo-projects/meetup/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ require('dotenv').config();
const express = require('express');

const { keystone, apps } = require('./index');
const initialData = require('./initialData');

const port = process.env.PORT || 3000;
const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/keystonejs-meetup';
Expand All @@ -17,6 +16,7 @@ keystone
// NOTE: This is only for demo purposes and should not be used in production
const users = await keystone.lists.User.adapter.findAll();
if (!users.length) {
const initialData = require('./initialData');
Object.values(keystone.adapters).forEach(async adapter => {
await adapter.dropDatabase();
});
Expand Down

0 comments on commit 086e582

Please sign in to comment.