Skip to content
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

Merged
merged 3 commits into from
Oct 2, 2017
Merged
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
17 changes: 9 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ module.exports = function (sails) {

initConnections: function () {
var connections = {}, connection, connectionName;
var datastore = sails.config.models.datastore || 'default';

Copy link
Owner

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

var connectionKey = sails.config.models.datastore ? 'datastore' : 'connection';

Copy link
Contributor Author

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.

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) {

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then use it everywhere like here:

for (connectionName in sails.config[connectionKey + 's']) {
...

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 = {};
Expand Down Expand Up @@ -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';
Copy link
Owner

Choose a reason for hiding this comment

The 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) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


modelClass = connections[connectionName].define(modelDef.globalId, modelDef.attributes, modelDef.options);

Expand Down Expand Up @@ -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');

Expand Down