node.js - 重命名 Sequelize 迁移表

标签 node.js migration sequelize.js

我在 migrations 中使用 Sequelize 和 CLI 命令,例如: sequelize db:migrate

如何配置 Sequelize 以使用不同的表名进行迁移,例如migrations 而不是 SequelizeMeta

看起来像 it could be configured 通过 umzug ,但是,我不知道如何使用 Sequelize 的 CLI 将此配置传递给它。

最佳答案

Umzug Sequelize storage options 是:

/**
 * @param {Object} [options]
 * @param {Object} [options.]
 * @param {Object} [options.sequelize] - configured instance of Sequelize.
 * @param {Object} [options.model] - Sequelize model - must have column name
 * matching "columnName" option.
 * @param {String} [options.modelName='SequelizeMeta'] - name of the model
 * to create if "model" option is not supplied.
 * @param {String} [options.tableName=modelName] - name of the table to create
 * if "model" option is not supplied.
 * @param {String} [options.schema=schema] - name of the schema to create
 * the table under, defaults to undefined.
 * @param {String} [options.columnName='name'] - name of the table column
 * holding migration name.
 * @param {String} [options.columnType=Sequelize.STRING] - type of the column.
 * For utf8mb4 charsets under InnoDB, you may need to set this <= 190.
 * @param {Boolean} [options.timestamps=false] - option to add timestamps to the model table
 */

因此,您可以在 Umzug 初始化时传递 tableName 选项:
import Umzug from 'umzug';

const  umzug = new Umzug({
  storage: 'sequelize',
  storageOptions: {
    sequelize, // your initialized sequelize instance
    tableName: 'sequelize_migrations', // your custom migrations table name
  },
  ... // other settings
});

关于node.js - 重命名 Sequelize 迁移表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35459191/

相关文章:

javascript - Google DRIVE API V3 - 使用 nodejs 获取根文件夹 ID

arrays - Mongoose - 填充二维数组

javascript - 从 URL 返回 innerHTML

asp.net-mvc - 如何将枚举值映射到查找表 - Code First

sequelize.js - Sequelize - 加入 varchar 和 varchar 数组

javascript - 从 div 属性获取变量值

ruby-on-rails - PG::UndefinedTable: 错误: 关系 "active_storage_blobs"不存在

maven - 将 Java 8 项目迁移到 Jigsaw 时我应该在哪里放置单元测试

javascript - Sequelize - 在 SQL 中使用 2 个地址作为外键的用户模型

node.js - 将 json 插入 Postgres 数据库时出现超时错误