From 9dde6960864f2e4c6d5738aef712a84206884db3 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 3 Sep 2021 10:40:00 +0300 Subject: [PATCH] btree index equals --- schema/diff.go | 6 ++++ schema/diff_test.go | 70 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/schema/diff.go b/schema/diff.go index b67dea7..d0b9ce3 100644 --- a/schema/diff.go +++ b/schema/diff.go @@ -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 } diff --git a/schema/diff_test.go b/schema/diff_test.go index 3e004a3..f403599 100644 --- a/schema/diff_test.go +++ b/schema/diff_test.go @@ -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) + } + }) + +}