Skip to content

Create index with comment generate invalid sql #79

@shelly-li-sl

Description

@shelly-li-sl

When creating a table with an index that has a comment, the generated 'create index' SQL is invalid.

===Test
type IndexWithComment struct {
ID int
Name string gorm:"size:20;index:idx_name_cmt,unique,comment:index for user name"
}
DB.Migrator().DropTable(&IndexWithComment{})
if err := DB.AutoMigrate(&IndexWithComment{}); err != nil {
t.Fatalf("failed to migrate, got %v", err)
}

if !DB.Migrator().HasIndex(&IndexWithComment{}, "idx_name_cmt") {
	t.Errorf("Failed to find created index")
}

===Generated SQL:
CREATE UNIQUE INDEX "idx_name_cmt" ON "index_with_comments"("name") COMMENT 'index for user name'

I think for 23ai, we should use ANNOTATIONS instead of COMMENT. And I think oracle doesn't support COMMENT ON index according to this doc:
https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/COMMENT.html

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions