Skip to content

Commit 39fb0fd

Browse files
committed
Added in validateOnBootstrap.
1 parent 1e95287 commit 39fb0fd

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

config/bootstrap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
module.exports.bootstrap = function(next) {
1616
// Check if we need to validate our schema
17-
if (sails.config.models.migrate === 'safe') { // aka PRODUCTION
17+
if (sails.config.models.validateOnBootstrap && sails.config.models.migrate === 'safe') { // aka PRODUCTION
1818
let waitingToFinish = 0;
1919

2020
_.forEach(sails.models, (model, modelName) => {

config/env/development.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ module.exports = {
2121
* environment (see config/datastores.js and config/models.js ) *
2222
***************************************************************************/
2323

24-
datastores: {
25-
host: process.env.DB_HOST || 'localhost',
26-
user: process.env.DB_USER || 'root',
27-
password: process.env.DB_PASS || 'mypass',
28-
database: process.env.DB_NAME || 'myapp',
29-
port: process.env.DB_PORT || 3306,
30-
ssl: (process.env.DB_SSL === 'true')
31-
},
24+
// datastores: {
25+
// host: process.env.DB_HOST || 'localhost',
26+
// user: process.env.DB_USER || 'root',
27+
// password: process.env.DB_PASS || 'mypass',
28+
// database: process.env.DB_NAME || 'myapp',
29+
// port: process.env.DB_PORT || 3306,
30+
// ssl: (process.env.DB_SSL === 'true')
31+
// },
3232

3333
models: {
3434
migrate: 'safe' // This is set as safe, so remote development machines are behaving like remote production machines. Use local.js to override.

config/models.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@ module.exports.models = {
104104
* *
105105
***************************************************************************/
106106

107-
cascadeOnDestroy: true
107+
cascadeOnDestroy: true,
108+
109+
110+
/********************************************************************************
111+
* *
112+
* This is a custom property, that is used inside of config/bootstrap.js. *
113+
* If set to true AND sails.config.models.migrate === 'safe', then the *
114+
* database schema validation and enforcement goes to work. If the database *
115+
* is not configured according to the model specifications, the problem areas *
116+
* will be console.error()'d, and Sails will fail to lift. This is intended for *
117+
* remote environments, to help prevent accidental deployment of an *
118+
* incompatible version for the given datastore. *
119+
* *
120+
********************************************************************************/
121+
validateOnBootstrap: true
108122

109123
};

0 commit comments

Comments
 (0)