问题
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