How can I set schema for all models at once at connection time for Sequelize Postgres?

孤街浪徒 提交于 2020-01-14 06:15:09

问题


I'm able to set schema for ad-hock queries with

sequelize.query(`
    SET SCHEMA 'schema_for_client_name'
`);

I'm also able to set schema for individual models

User.init(
    {
      userId: {
        type: DataTypes.INTEGER,
        autoIncrement: true,
        primaryKey: true,
      },
      email: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      firstName: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      lastName: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      password: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      salt: {
        type: DataTypes.STRING,
        allowNull: false,
      },
    },
    {
      sequelize,
      tableName: 'users',
      schema: 'schema_for_client_name',
      timestamps: false,
    }
);

Is it possible to set schema for all models at once at connection time?


回答1:


According to the docs the Sequelize constructor takes an optional default schema option:

const sequelize = new Sequelize(database, username, password, {schema: 'schema_for_client_name'});


来源:https://stackoverflow.com/questions/58070444/how-can-i-set-schema-for-all-models-at-once-at-connection-time-for-sequelize-pos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!