Skip to content

Commit

Permalink
Fix possible panic when comment not quoted, close #134
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Oct 8, 2022
1 parent af97cb4 commit 0d0e3a2
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions migrator.go
Expand Up @@ -249,10 +249,9 @@ func (m Migrator) MigrateColumn(value interface{}, field *schema.Field, columnTy
checkSQL += "AND objoid = (SELECT oid FROM pg_catalog.pg_class WHERE relname = ? AND relnamespace = "
checkSQL += "(SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = ?))"
m.DB.Raw(checkSQL, values...).Scan(&description)
comment := field.Comment
if comment != "" {
comment = comment[1 : len(comment)-1]
}

comment := strings.Trim(field.Comment, "'")
comment = strings.Trim(comment, `"`)
if field.Comment != "" && comment != description {
if err := m.DB.Exec(
"COMMENT ON COLUMN ?.? IS ?",
Expand Down

0 comments on commit 0d0e3a2

Please sign in to comment.