Search code examples
node.jspostgresqlknex.js

How to use knex alertableBuilder to update column comment


The migration file is below:

import * as Knex from 'knex';
exports.up = async (knex: Knex): Promise<any> => {
  await knex.schema.raw(`
  COMMENT on "USER".user_invite_state is '0 - not sent invitation email, 1 - sent without acknowledged, 2 - sent with acknowledged, 3 - invite failed';
  `);
};
exports.down = async (knex: Knex): Promise<any> => {};

When i do knex migration, i got the error as below: migration failed with error: COMMENT on "USER".user_invite_state is '0 - not sent invitation email, 1 - sent without acknowledged, 2 - sent with acknowledged, 3 - invite failed'; - syntax error at or near "COMMENT on " error: syntax error at or near "COMMENT on "

Does anyone have any ideas about this?


Solution

  • You should work with the queryBuilder, it whole purpose it to bridge between different db syntaxes.

    export async function up(knex: Knex) {
      await knex.schema.alterTable(tn, t => {
        t.integer('colName')
          .comment('this is my comment')
          .alter();
      });
    }