我试图始终使用 sequelize 和 umzug 运行迁移到特定的 postgresql 数据库模式。让我们称之为custom模式。默认情况下,所有查询都转到public架构。
有什么方法可以定义默认模式以在 sequelize 或 umzug 中运行所有迁移?
使用以下代码,我可以为迁移中的单个查询定义架构:
// schema defined according to https://sequelize.readthedocs.io/en/latest/docs/migrations/
module.exports = {
up: async (queryInterface, Sequelize) => {
return Sequelize.transaction(async transaction => {
await queryInterface.renameTable({ tableName: 'oldtablename', schema: "custom"}, 'newtablename', { transaction })
})
},
down: async () => {
}
}
Run Code Online (Sandbox Code Playgroud)
它报告它成功并使用正确的模式:
Migration {
path:
'path/to/migrations/migration_test.js',
file: 'migration_test.js',
options:
{ storage: 'sequelize',
storageOptions: [Object],
logging: [Function: bound consoleCall],
upName: 'up',
downName: 'down', …Run Code Online (Sandbox Code Playgroud)