javascript - Sequalizejs 向现有表添加偏执配置

标签 javascript node.js sequelize.js

我创建了一个没有 paranoid 选项的表,现在我想更改该表的定义以使用 paranoid。

我不想重新创建数据库,因为它已经在生产中了。 我如何使用迁移来做到这一点?

我应该将 addColumn 与 deletedAt 一起使用并将偏执定义添加到模型中,还是有更好的方法?

最佳答案

我使用这样的迁移添加了 deletedAt 字段:

"use strict";

module.exports = {
  up: function(migration, DataTypes, done) {
    // add altering commands here, calling 'done' when finished

      migration.addColumn(
          'mytablename',
          'deletedAt',
          {
              type: DataTypes.DATE,
              allowNull: true,
              validate: {
              }
          }
      );
    done();
  },

  down: function(migration, DataTypes, done) {
    // add reverting commands here, calling 'done' when finished
    migration.removeColumn('mytablename', 'deletedAt');
    done();
  }
};

并添加配置:

 paranoid: true,

我的模型

这似乎有效。

有没有人有更好的解决方案?

关于javascript - Sequalizejs 向现有表添加偏执配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27292521/

相关文章:

javascript - 如何删除括号和括号内的内容?

javascript - 将新行 ' ' 自动添加到 select 选项

javascript - 从下拉列表中选择值后 MVC 重新加载页面

javascript - 为什么 translate3d 会泄漏 DOM 节点?

node.js - Mongoose API 通过 _id 获取数组中的嵌套项

postgresql - Feathers-Sequelize 与 Postgres : How to query an Array

sequelize.js - sequelize 使用外键创建记录

node.js - 有没有一种编程方式可以知道 node.js 应用程序正在 Heroku 中运行?

node.js - postgres + sequelize + node,使用凭据连接到主机

typescript - "schemaName"。 "tableName"生成 "schemaName.tableName"- Sequelize - Postgres