Gorm V1 提供 AddIndex 和 AddUniqueIndex方法可以手动添加索引。旧项目用此方法:例如 Gorm AddIndex 方法问题

现在想升级gorm v2,貌似可以用Migrator.CreateIndex, 但是有几个问题: 1.要必须在struct字段添加tag,如果同个字段建多个索引,或者多个字段复合索引,tag会变得很长很长,可读性很差;添加的索引变得很不直观。 2.那假如索引不加名字只加index或uniqueIndex,那这样CreateIndex时就只会查询有tag的字段统一建索引,也不能多个自定义索引。 3.假如要加的索引有用到gorm.Model里的ID或者created_at等字段,难道要修改model里的字段添加tag? 不合理。 4.如上图中,假如要添加where条件添加索引,目前好像也不好处理。

因此只能手动原生sql来创建索引,但是这样的索引有很多个,全都这样创建不现实容易出错,况且本来想升级v2就是不想手动拼batchCreate Sql,现在升级v2反而要手动拼接创索引sql, 有点本末倒置了。

能否请求重新添加AddIndex方法

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking