我在Sequelize中通过命令行界面命令使用migrations,例如:sequelize db:migrate。
如何配置Sequelize以使用不同的表名进行迁移,例如migrations而不是SequelizeMeta
看起来像是通过umzug的it could be configured,但是,我不知道如何使用Sequelize的命令行界面将这个配置传递给它。
发布于 2019-06-21 03:09:17
快进(3年),但将是有用的:
在config.json或config.js中(取决于是否需要dynamic configuration )添加选项
"migrationStorageTableName": "your_name_for_migration_tables" ( Default: SequelizeMeta )除了缺省的
"development": {
"username": "root",
"password": null,
"database": "database_development",
"host": "127.0.0.1",
"dialect": "mysql", }有关详细说明,请阅读manual。
发布于 2018-03-13 04:35:28
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
});发布于 2016-09-16 06:09:43
对于那些不知道的人,也花了一些时间来弄清楚。必须查看umzug的测试才能了解发生了什么。
设置尽可能接近sequelize-cli (还必须深入研究sequilize-cli ),因此您不必更改迁移文件。
我正在使用TypeScript,我希望理解它是如何工作的不是问题。
import * as Sequelize from "sequelize";
import * as Umzug from "umzug";
let dbConfig = {
"dialect": "sqlite",
"storage": "test.db",
"seederStorage": "sequelize"
},
let sequelize = new Sequelize(dbName, username, password, dbConfig);
let umzug = new Umzug({
storage: "sequelize",
storageOptions: {
sequelize: sequelize,
// tableName: "migrations"
tableName: "SequelizeData" // default table name for sequelize-cli `seeder`
},
migrations: {
path: "built/migrations/seeder",
params: [sequelize.getQueryInterface(), sequelize.Sequelize] // arguments for `up` and `down`
}
});
...
umzug.up();
umzug.down();
...迁移文件:
module.exports = {
up: function (queryInterface: QueryInterface, sequelize: DataTypes) {
return queryInterface.bulkInsert("some_table", {});
},
down: function (queryInterface: QueryInterface, sequelize: DataTypes) {
return queryInterface.bulkDelete("some_table", {});
}
};https://stackoverflow.com/questions/35459191
复制相似问题