小编Roc*_*et2的帖子

使用 postgres 和 umzug 时如何为续集迁移定义默认架构?

我试图始终使用 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)

postgresql sequelize.js umzug

3
推荐指数
1
解决办法
2736
查看次数

标签 统计

postgresql ×1

sequelize.js ×1

umzug ×1