github.com/wawandco/oxpecker@v1.5.7-0.20210910201653-5958d4afdd89/tools/soda/fizz/drop_index.go (about) 1 package fizz 2 3 import ( 4 "fmt" 5 "regexp" 6 ) 7 8 var diReg = regexp.MustCompile(`drop_index_(\w+)_from_(\w+)`) 9 10 type dropIndex struct { 11 index string 12 table string 13 } 14 15 func (di dropIndex) match(name string) bool { 16 return diReg.MatchString(name) 17 } 18 19 func (di *dropIndex) GenerateFizz(name string, args []string) (string, string, error) { 20 matches := diReg.FindAllStringSubmatch(name, -1)[0][1:] 21 di.index = matches[0] 22 di.table = matches[1] 23 24 return di.fizz(), di.unFizz(), nil 25 } 26 27 func (di dropIndex) fizz() string { 28 return fmt.Sprintf(`drop_index("%s", "%s")`, di.table, di.index) 29 } 30 31 func (di dropIndex) unFizz() string { 32 return fmt.Sprintf(`add_index("%s", "%s", {})`, di.table, di.index) 33 }