Skip to content

How to do migration when index added #2766

Answered by simolus3
HasanAlqaisi asked this question in Q&A
Discussion options

You must be logged in to vote

You can create the index separately in the migration. Drift will generate a getter in the database class for indices added to tables based on the name in the TableIndex annotation. So you can do

onUpgrade: (m, from, to) async {
  if (...) {
    await m.addColumn(table, table.newColumn);
    await m.create(tableIndex);
  }
}

There's been a bug fixed in drift_dev 2.14.0 causing the getter to not be added in some cases - if you don't have it in your database, please try upgrading.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by HasanAlqaisi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants