-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update sailsjs configuration format to support v1. #36
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,15 +50,16 @@ module.exports = function (sails) { | |
|
||
initConnections: function () { | ||
var connections = {}, connection, connectionName; | ||
var datastore = sails.config.models.datastore || 'default'; | ||
|
||
sails.log.verbose('Using default connection named ' + sails.config.models.connection); | ||
if (!sails.config.connections[sails.config.models.connection]) { | ||
throw new Error('Default connection \'' + sails.config.models.connection + '\' not found in config/connections'); | ||
sails.log.verbose('Using default connection named ' + datastore); | ||
if (!sails.config.datastores[datastore]) { | ||
throw new Error('Default connection \'' + datastore + '\' not found in config/connections'); | ||
} | ||
|
||
for (connectionName in sails.config.connections) { | ||
for (connectionName in sails.config.datastores) { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And then use it everywhere like here:
This allow us for supporting both pre v1.0 versions along with v1.0 |
||
connection = sails.config.connections[connectionName]; | ||
connection = sails.config.datastores[connectionName]; | ||
|
||
if (!connection.options) { | ||
connection.options = {}; | ||
|
@@ -96,7 +97,7 @@ module.exports = function (sails) { | |
modelDef = models[modelName]; | ||
sails.log.verbose('Loading model \'' + modelDef.globalId + '\''); | ||
|
||
connectionName = modelDef.options.connection || sails.config.models.connection; | ||
connectionName = modelDef.datastore || sails.config.models.datastore || 'default'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in v1.0 datastore is now located in model definition root? (instead of .options, like in v0.12) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
modelClass = connections[connectionName].define(modelDef.globalId, modelDef.attributes, modelDef.options); | ||
|
||
|
@@ -156,8 +157,8 @@ module.exports = function (sails) { | |
} else { | ||
forceSync = migrate === 'drop'; | ||
|
||
for (connectionName in sails.config.connections) { | ||
connectionDescription = sails.config.connections[connectionName]; | ||
for (connectionName in sails.config.datastores) { | ||
connectionDescription = sails.config.datastores[connectionName]; | ||
|
||
sails.log.verbose('Migrating schema in \'' + connectionName + '\' connection'); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm.... Why not to define a key for searching connection properties, like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated it already to support both variants of sails. Please have a look.