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

Problem if datastores > 1 #68

Closed
Droppix opened this issue Dec 20, 2019 · 1 comment
Closed

Problem if datastores > 1 #68

Droppix opened this issue Dec 20, 2019 · 1 comment

Comments

@Droppix
Copy link

Droppix commented Dec 20, 2019

Hi,

You have a problem of synchronization on the name connection, in index.js (line 256):

if (connectionDescription.dialect === 'postgres') {

    syncTasks.push(connections[connectionName].showAllSchemas().then(schemas => {
        let modelName, modelDef, tableSchema;

        for (modelName in models) {
            modelDef = models[modelName];
            tableSchema = modelDef.options.schema || '';

            if (tableSchema !== '' && schemas.indexOf(tableSchema) < 0) { // there is no schema in db for model
                connections[connectionName].createSchema(tableSchema);
                schemas.push(tableSchema);
            }
        }

        return connections[connectionName].sync({ force: forceSyncFlag, alter: alterFlag });
    }));

} else {}

Since "syncTasks" can take some time, connectionName can contain a wrong value, in my case it contains the last item of the data array.
Your must replace by this :

if (connectionDescription.dialect === 'postgres') {
    let cn = connectionName
    syncTasks.push(connections[cn].showAllSchemas().then(schemas => {
        let modelName, modelDef, tableSchema;

        for (modelName in models) {
            modelDef = models[modelName];
            tableSchema = modelDef.options.schema || '';

            if (tableSchema !== '' && schemas.indexOf(tableSchema) < 0) { // there is no schema in db for model
                connections[cn].createSchema(tableSchema);
                schemas.push(tableSchema);
            }
        }

        return connections[cn].sync({ force: forceSyncFlag, alter: alterFlag });
    }));
} else {

For reproduction, you must have several datastore in file : config/datastores.js

module.exports.datastores = {

  sequelizeHost: {
    user: '',
    password: '',
    database: '',
    dialect: 'postgres',
    options: {
        dialect: 'postgres',
        host   : '',
        port   : x,
        logging: false,
        operatorsAliases: false,
        dialectOptions: {
          ssl: true
        }    
    }        
  },

  sequelizeDev: {
    adapter: {}, // force to skip
    user: '',
    password: '',
    database: '',
    options: {
        dialect: 'postgres',
        host   : 'localhost',
        port   : 5432,
        logging: false,
        operatorsAliases: false
    }
  },

  sequelizeTests: {
    adapter: {}, // force to skip
    user: '',
    password: '',
    database: '',
    options: {
        dialect: 'postgres',
        host   : 'localhost',
        port   : 5432,
        logging: false,
        operatorsAliases: false
    }
  }
};

and in the config/models .js :

connection: 'sequelizeHost'

So, it would be nice to have an option that would inhibit a connection (in order for it to work, I had to add -> adapter : {})

@KSDaemon
Copy link
Owner

KSDaemon commented Dec 20, 2019

Hi @Droppix ! Thanks for pointing out. I've fixed it.
I don't see any reason to introduce new option, as if you do not need a datastore connection in you app — simply remove (or comment out) it :)
And using adapter attribute i'm trying to figure out what connections are waterline, so i skip them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants