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) + } + }) + +}