Skip to content

Commit f6da78f

Browse files
committed
fix(server:seed): user seed not executing
For projects with auth=Y, users were not being populated for those using Sequelize because of the return on Think.bulkCreate. The return was changed to a Sequelize.Promise.all so that all the promises are properly managed.
1 parent 9473d81 commit f6da78f

File tree

1 file changed

+56
-59
lines changed

1 file changed

+56
-59
lines changed

Diff for: templates/app/server/config/seed(models).js

+56-59
Original file line numberDiff line numberDiff line change
@@ -6,70 +6,67 @@
66
'use strict';<% if (filters.mongooseModels) { %>
77
import Thing from '../api/thing/thing.model';<% if (filters.auth) { %>
88
import User from '../api/user/user.model';<% } %><% } %><% if (filters.sequelizeModels) { %>
9-
import sqldb from '../sqldb';<% } %>
9+
import { Thing<% if (filters.auth) { %>, User<% } %> } from '../sqldb';<% if (filters.auth) { %>
10+
import Sequelize from 'sequelize';<% } %><% } %>
1011
import config from './environment/';
1112

1213
export default function seedDatabaseIfNeeded() {
1314
if(config.seedDB) {
14-
<% if (filters.sequelizeModels) { %>let Thing = sqldb.Thing;<% if (filters.auth) { %>
15-
let User = sqldb.User;<% } %><% } %>
16-
1715
<% if (filters.mongooseModels) { %>Thing.find({}).remove()<% }
18-
if (filters.sequelizeModels) { %>return Thing.destroy({ where: {} })<% } %>
19-
.then(() => {
20-
<% if (filters.mongooseModels) { %>Thing.create({<% }
21-
if (filters.sequelizeModels) { %>return Thing.bulkCreate([{<% } %>
22-
name: 'Development Tools',
23-
info: 'Integration with popular tools such as Webpack, Gulp, Babel, TypeScript, Karma, '
24-
+ 'Mocha, ESLint, Node Inspector, Livereload, Protractor, Pug, '
25-
+ 'Stylus, Sass, and Less.'
26-
}, {
27-
name: 'Server and Client integration',
28-
info: 'Built with a powerful and fun stack: MongoDB, Express, '
29-
+ 'AngularJS, and Node.'
30-
}, {
31-
name: 'Smart Build System',
32-
info: 'Build system ignores `spec` files, allowing you to keep '
33-
+ 'tests alongside code. Automatic injection of scripts and '
34-
+ 'styles into your index.html'
35-
}, {
36-
name: 'Modular Structure',
37-
info: 'Best practice client and server structures allow for more '
38-
+ 'code reusability and maximum scalability'
39-
}, {
40-
name: 'Optimized Build',
41-
info: 'Build process packs up your templates as a single JavaScript '
42-
+ 'payload, minifies your scripts/css/images, and rewrites asset '
43-
+ 'names for caching.'
44-
}, {
45-
name: 'Deployment Ready',
46-
info: 'Easily deploy your app to Heroku or Openshift with the heroku '
47-
+ 'and openshift subgenerators'
48-
<% if (filters.mongooseModels) { %>});<% }
49-
if (filters.sequelizeModels) { %>}]);<% } %>
50-
})
51-
.then(() => console.log('finished populating things'))
52-
.catch(err => console.log('error populating things', err));
53-
<% if (filters.auth) { %>
16+
if (filters.sequelizeModels) { %>return <% if (filters.auth) { %>Sequelize.Promise.all([
17+
<% } %>Thing.destroy({ where: {} })<% } %>
18+
.then(() =><% if (filters.mongooseModels) { %> {
19+
Thing.create({<% } if (filters.sequelizeModels) { %>
20+
Thing.bulkCreate([{<% } %>
21+
name: 'Development Tools',
22+
info: 'Integration with popular tools such as Webpack, Gulp, Babel, TypeScript, Karma, '
23+
+ 'Mocha, ESLint, Node Inspector, Livereload, Protractor, Pug, '
24+
+ 'Stylus, Sass, and Less.'
25+
}, {
26+
name: 'Server and Client integration',
27+
info: 'Built with a powerful and fun stack: MongoDB, Express, '
28+
+ 'AngularJS, and Node.'
29+
}, {
30+
name: 'Smart Build System',
31+
info: 'Build system ignores `spec` files, allowing you to keep '
32+
+ 'tests alongside code. Automatic injection of scripts and '
33+
+ 'styles into your index.html'
34+
}, {
35+
name: 'Modular Structure',
36+
info: 'Best practice client and server structures allow for more '
37+
+ 'code reusability and maximum scalability'
38+
}, {
39+
name: 'Optimized Build',
40+
info: 'Build process packs up your templates as a single JavaScript '
41+
+ 'payload, minifies your scripts/css/images, and rewrites asset '
42+
+ 'names for caching.'
43+
}, {
44+
name: 'Deployment Ready',
45+
info: 'Easily deploy your app to Heroku or Openshift with the heroku '
46+
+ 'and openshift subgenerators'
47+
}<% if (filters.sequelizeModels) { %>]<% } %>)<% if (filters.mongooseModels) { %>;
48+
}<% } %>)
49+
.then(() => console.log('seeded things'))<% if (filters.sequelizeModels && filters.auth) { %>,<% } if (filters.auth) { %>
5450
<% if (filters.mongooseModels) { %>User.find({}).remove()<% }
55-
if (filters.sequelizeModels) { %>User.destroy({ where: {} })<% } %>
56-
.then(() => {
57-
<% if (filters.mongooseModels) { %>User.create({<% }
58-
if (filters.sequelizeModels) { %>return User.bulkCreate([{<% } %>
59-
provider: 'local',
60-
name: 'Test User',
61-
62-
password: 'test'
63-
}, {
64-
provider: 'local',
65-
role: 'admin',
66-
name: 'Admin',
67-
68-
password: 'admin'
69-
<% if (filters.mongooseModels) { %>})<% }
70-
if (filters.sequelizeModels) { %>}])<% } %>
71-
.then(() => console.log('finished populating users'))
72-
.catch(err => console.log('error populating users', err));<% } %>
73-
});
51+
if (filters.sequelizeModels) { %> User.destroy({ where: {} })<% } %>
52+
.then(() =><% if (filters.mongooseModels) { %> {<% } %>
53+
<% if (filters.mongooseModels) { %>User.create({<% }
54+
if (filters.sequelizeModels) { %>User.bulkCreate([{<% } %>
55+
provider: 'local',
56+
name: 'Test User',
57+
58+
password: 'test'
59+
}, {
60+
provider: 'local',
61+
role: 'admin',
62+
name: 'Admin',
63+
64+
password: 'admin'
65+
}<% if (filters.mongooseModels) { %>);
66+
})<% }
67+
if (filters.sequelizeModels) { %>])<% } %>
68+
.then(() => console.log('seeded users'))<% if (filters.sequelizeModels) { %>)])
69+
.then(() => console.log('seeded database'))<% } %><% } %>
70+
<% if (filters.sequelizeModels && !filters.auth) { %> <% } %><% if (filters.mongooseModels) { %> <% } %>.catch(err => console.log('Seeding error: ', err));
7471
}
7572
}

0 commit comments

Comments
 (0)