Adam Baranyai
Adam Baranyai

Reputation: 3867

How to update the collation of a mariadb column via sequelize changeColumn method in migrations?

I am using sequelize to perform migrations on my database. I would like to change the collation of a column in an existing table via a migration file, but I don't find where should I put this information. I've searched in the documentation to no avail, and neither does my intellisense give me any info when trying to write the code in typescript.

export async function up(queryInterface: QueryInterface, Sequelize: Sequelize) {
   await queryInterface.changeColumn('PageHits', 'SessionId', {
       /** I want to change this columns collation **/
   });
}

Under what property should I put the collation information into?

Upvotes: 0

Views: 527

Answers (1)

doublesharp
doublesharp

Reputation: 27609

Pass the collate value into the changeColumn() options. You should list the "before" and "after" as the same column name.

export async function up(queryInterface: QueryInterface, Sequelize: Sequelize) {
   const collate = 'your collation';

   await queryInterface.changeColumn(
     'PageHits',  // table name
     'SessionId', // before column name
     'SessionId', // after column name
     {
       collate,   // collation
     },
   });
}

Upvotes: 1

Related Questions