Skip to content

Commit

Permalink
Sort columns when create comments (#217)
Browse files Browse the repository at this point in the history
* Sort columns comments

* Simplify m.Migrator.CreateTable columns sortomg
  • Loading branch information
artemklevtsov authored Oct 10, 2023
1 parent f437ffe commit f538e03
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ func (m Migrator) CreateTable(values ...interface{}) (err error) {
for _, value := range m.ReorderModels(values, false) {
if err = m.RunWithValue(value, func(stmt *gorm.Statement) error {
if stmt.Schema != nil {
for _, field := range stmt.Schema.FieldsByDBName {
for _, fieldName := range stmt.Schema.DBNames {
field := stmt.Schema.FieldsByDBName[fieldName]
if field.Comment != "" {
if err := m.DB.Exec(
"COMMENT ON COLUMN ?.? IS ?",
Expand Down

0 comments on commit f538e03

Please sign in to comment.