forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.go
65 lines (59 loc) · 1.19 KB
/
index.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package fizz
import (
"fmt"
"strings"
)
type Index struct {
Name string
Columns []string
Unique bool
Options Options
}
func (f fizzer) AddIndex() interface{} {
return func(table string, columns interface{}, options Options) {
i := Index{}
switch t := columns.(type) {
default:
fmt.Printf("unexpected type %T\n", t) // %T prints whatever type t has
case string:
i.Columns = []string{t}
case []interface{}:
cl := make([]string, len(t))
for i, c := range t {
cl[i] = c.(string)
}
i.Columns = cl
}
if options["name"] != nil {
i.Name = options["name"].(string)
} else {
i.Name = fmt.Sprintf("%s_%s_idx", table, strings.Join(i.Columns, "_"))
}
i.Unique = options["unique"] != nil
f.add(f.Bubbler.AddIndex(Table{
Name: table,
Indexes: []Index{i},
}))
}
}
func (f fizzer) DropIndex() interface{} {
return func(table, name string) {
f.add(f.Bubbler.DropIndex(Table{
Name: table,
Indexes: []Index{
{Name: name},
},
}))
}
}
func (f fizzer) RenameIndex() interface{} {
return func(table, old, new string) {
f.add(f.Bubbler.RenameIndex(Table{
Name: table,
Indexes: []Index{
{Name: old},
{Name: new},
},
}))
}
}