dialect/sql/schema: avoid setting the primary key when no primary key is present (#3114)

* dialect/sql: avoid setting the primary key when no primary key is present

* fix tests

* adds comment
This commit is contained in:
Pedro Henrique
2022-11-28 01:48:00 -03:00
committed by GitHub
parent bc931edddf
commit 397afc3d85
2 changed files with 6 additions and 3 deletions

View File

@@ -979,7 +979,10 @@ func (a *Atlas) aIndexes(et *Table, at *schema.Table) error {
}
pk = append(pk, c2)
}
at.SetPrimaryKey(schema.NewPrimaryKey(pk...))
// CreateFunc might clear the primary keys.
if len(pk) > 0 {
at.SetPrimaryKey(schema.NewPrimaryKey(pk...))
}
// Rest of indexes.
for _, idx1 := range et.Indexes {
idx2 := schema.NewIndex(idx1.Name).