Skip to content

Commit

Permalink
Merge pull request #3 from gamedolphin/bug/patch-relation
Browse files Browse the repository at this point in the history
fix: also use table name to find correct relation to alter
  • Loading branch information
covrom authored Jun 26, 2022
2 parents a95fe7d + 7e38dc9 commit 5b7c18b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions schema/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ func (s *PatchSchema) Build(from, to *Schema) {
pt := &PatchRelation{
from: r,
}
rt, err := to.FindRelation(r.Columns, r.ParentColumns)
rt, err := to.FindRelation(r.Table.Name, r.Columns, r.ParentColumns)
if err == nil {
pt.to = rt
}
Expand All @@ -604,7 +604,7 @@ func (s *PatchSchema) Build(from, to *Schema) {
pt := &PatchRelation{
to: r,
}
_, err := from.FindRelation(r.Columns, r.ParentColumns)
_, err := from.FindRelation(r.Table.Name, r.Columns, r.ParentColumns)
if err != nil {
s.relations = append(s.relations, pt)
}
Expand Down
4 changes: 2 additions & 2 deletions schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ func (s *Schema) FindTableByName(name string) (*Table, error) {
}

// FindRelation ...
func (s *Schema) FindRelation(cs, pcs []*Column) (*Relation, error) {
func (s *Schema) FindRelation(tblName string, cs, pcs []*Column) (*Relation, error) {
L:
for _, r := range s.Relations {
if len(r.Columns) != len(cs) || len(r.ParentColumns) != len(pcs) {
if len(r.Columns) != len(cs) || len(r.ParentColumns) != len(pcs) || r.Table.Name != tblName {
continue
}
for _, rc := range r.Columns {
Expand Down

0 comments on commit 5b7c18b

Please sign in to comment.