'Add a new column and also index it using knex?

I have a simple knext migration to add a new column:

import * as Knex from "knex";

export async function up(knex: Knex): Promise<void> {
  await knex.schema.alterTable("bins", (table) => {
    table.bigInteger("parent_lsn").defaultTo(null).after("lsn").index();
  });
}

export async function down(knex: Knex): Promise<void> {
  await knex.schema.alterTable("bins", (table) => {
    table.dropColumns("parent_lsn");
  });
}

I tried adding the .index() in there, but it's not seeming to reflect as an indexed column in the database. Not sure where I'm going wrong here?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source