-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
migrate_es_index_pattern.go
34 lines (29 loc) · 1.21 KB
/
migrate_es_index_pattern.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
package migrate
import (
"github.com/toolkits/pkg/logger"
"gorm.io/gorm"
)
type EsIndexPattern struct {
Id int64 `gorm:"primaryKey;type:bigint unsigned"`
DatasourceId int64 `gorm:"type:bigint not null default '0';uniqueIndex:idx_ds_name"`
Name string `gorm:"type:varchar(191) not null default '';uniqueIndex:idx_ds_name"`
TimeField string `gorm:"type:varchar(128) not null default ''"`
AllowHideSystemIndices int `gorm:"type:tinyint(1) not null default 0"`
FieldsFormat string `gorm:"type:varchar(4096) not null default ''"`
CreateAt int64 `gorm:"type:bigint default '0'"`
CreateBy string `gorm:"type:varchar(64) default ''"`
UpdateAt int64 `gorm:"type:bigint default '0'"`
UpdateBy string `gorm:"type:varchar(64) default ''"`
}
func MigrateEsIndexPatternTable(db *gorm.DB) error {
db = db.Set("gorm:table_options", "CHARSET=utf8mb4")
if db.Migrator().HasTable("es_index_pattern") {
return nil
}
err := db.Table("es_index_pattern").AutoMigrate(&EsIndexPattern{})
if err != nil {
logger.Errorf("failed to migrate es index pattern table: %v", err)
return err
}
return nil
}