Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequalizejs adding paranoid configuration to an existing table

I created a table without the paranoid option, and i now want to change that table's definition to use paranoid.

I don't want to re-create the database since its already in production. how can i do that using migrations?

should i use addColumn with deletedAt and just add the paranoid definition to the model, or is there a better way?

like image 742
Kinnza Avatar asked Dec 04 '14 11:12

Kinnza


1 Answers

I added the deletedAt field using migration like this:

"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();
  }
};

And added the configuration:

 paranoid: true,

to my model

It seems to work.

Does anyone have a better solution?

like image 108
Kinnza Avatar answered Nov 03 '22 09:11

Kinnza