-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.go
41 lines (36 loc) · 811 Bytes
/
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
package ddltable
import (
"fmt"
"strings"
)
type index struct {
Type string
ColumnNames []string
}
func (ix index) migrationUp() func(nameTable, nameIndex string) string {
if len(ix.Type) == 0 {
return func(nameTable, nameIndex string) string {
return fmt.Sprintf(
"create index if not exists %s on %s(\n"+strings.Join(ix.ColumnNames, ",\n")+"\n);",
nameIndex,
nameTable,
)
}
}
return func(nameTable, nameIndex string) string {
return fmt.Sprintf(
"create %s index if not exists %s on %s(\n"+strings.Join(ix.ColumnNames, ",\n")+"\n);",
ix.Type,
nameIndex,
nameTable,
)
}
}
func (ix index) migrationDown() func(nameIndex string) string {
return func(nameIndex string) string {
return fmt.Sprintf(
"drop index if exists %s;",
nameIndex,
)
}
}