Skip to content
This repository was archived by the owner on Jul 29, 2026. It is now read-only.
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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().
  • Loading branch information
nstuyvesant committed Feb 1, 2017
commit d0fad3ef876f0d0d43eb1c7271e7b1387b657e71
8 changes: 4 additions & 4 deletions templates/app/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ function startServer() {
});
}
<% if(filters.sequelize) { %>
sqldb.sequelize.sync()
sqldb.sequelize.sync()<% if(filters.models) { %>
.then(seedDatabaseIfNeeded)<% } %>
.then(startServer)
<% if(filters.models) { %> .then(seedDatabaseIfNeeded)<% } %>
.catch(function(err) {
console.log('Server failed to start due to error: %s', err);
});
<% } else { %>
seedDatabaseIfNeeded();
<% } else { %><% if(filters.models) { %>
seedDatabaseIfNeeded();<% } %>
setImmediate(startServer);
<% } %>
// Expose app
Expand Down