Skip to content

Commit

Permalink
btree index equals
Browse files Browse the repository at this point in the history
  • Loading branch information
covrom committed Sep 3, 2021
1 parent 3e04d16 commit 9dde696
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
6 changes: 6 additions & 0 deletions schema/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ func (i *PatchIndex) create() []string {
return []string{createIndexDDL(i.to)}
}
func (i *PatchIndex) alter() []string {
if i.from.MethodName == "" {
i.from.MethodName = "btree"
}
if i.to.MethodName == "" {
i.to.MethodName = "btree"
}
if strings.EqualFold(createIndexDDL(i.from), createIndexDDL(i.to)) {
return nil
}
Expand Down
70 changes: 70 additions & 0 deletions schema/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,73 @@ CREATE INDEX table1_col2 ON table1(column2,column3)` {
})

}

func TestPatchSchema_BuildChangeIdx2(t *testing.T) {
from := &Schema{
CurrentSchema: "public",
Tables: []*Table{
{
Name: "projects",
Type: "TABLE",
Columns: []*Column{
{
Name: "id",
Type: "uuid",
PrimaryKey: true,
},
{
Name: "deleted_at",
Type: "timestamptz",
Nullable: true,
},
},
Indexes: []*Index{
{
Name: "projects_deleted_at",
MethodName: "btree",
Columns: []string{"deleted_at"},
},
},
},
},
}

to := &Schema{
CurrentSchema: "public",
Tables: []*Table{
{
Name: "projects",
Type: "TABLE",
Columns: []*Column{
{
Name: "id",
Type: "uuid",
PrimaryKey: true,
},
{
Name: "deleted_at",
Type: "timestamptz",
Nullable: true,
},
},
Indexes: []*Index{
{
Name: "projects_deleted_at",
Columns: []string{"deleted_at"},
},
},
},
},
}

t.Run("1", func(t *testing.T) {
s := &PatchSchema{}
s.Build(from, to)
qs := s.GenerateSQL()
qss := strings.Join(qs, "\n")
if qss != `` {
t.Error(qss)
}
})

}

0 comments on commit 9dde696

Please sign in to comment.