Skip to content

Commit d0fad3e

Browse files
committed
fix (app): prevent excess sync() calls during seed
Previously, .sync() was being called once in server/config/seed.js and once during sqldb.sequelize.sync() in server/app.js. As a result, duplicate queries were being sent to the database if the tables needed to be defined causing an error when it tries to define constraints a second time (like for an identity column). Seed.js is wrapped in a function and contains the conditional to determine whether to seed the database. This makes it easy to include in the promise chain under sqldb.sequelize.sync().
1 parent 42ec90a commit d0fad3e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: templates/app/server/app.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ function startServer() {
3737
});
3838
}
3939
<% if(filters.sequelize) { %>
40-
sqldb.sequelize.sync()
40+
sqldb.sequelize.sync()<% if(filters.models) { %>
41+
.then(seedDatabaseIfNeeded)<% } %>
4142
.then(startServer)
42-
<% if(filters.models) { %> .then(seedDatabaseIfNeeded)<% } %>
4343
.catch(function(err) {
4444
console.log('Server failed to start due to error: %s', err);
4545
});
46-
<% } else { %>
47-
seedDatabaseIfNeeded();
46+
<% } else { %><% if(filters.models) { %>
47+
seedDatabaseIfNeeded();<% } %>
4848
setImmediate(startServer);
4949
<% } %>
5050
// Expose app

0 commit comments

Comments
 (0)