gpt4 book ai didi

node.js - 重命名 Sequelize 迁移表

转载 作者:行者123 更新时间:2023-12-03 22:23:58 27 4
gpt4 key购买 nike

我在 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com