Files
atom/database/migrations/20230131_165134_create_sys_dictionary.go
2023-02-05 13:30:43 +08:00

51 lines
1.3 KiB
Go
Executable File

package migrations
import (
"atom/container"
"atom/contracts"
"atom/providers/log"
"go.uber.org/dig"
"gorm.io/gorm"
)
func init() {
if err := container.Container.Provide(New20230131_165134CreateSysDictionaryMigration, dig.Group("migrations")); err != nil {
log.Fatal(err)
}
}
type Migration20230131_165134CreateSysDictionary struct {
id string
}
func New20230131_165134CreateSysDictionaryMigration() contracts.Migration {
return &Migration20230131_165134CreateSysDictionary{id: "20230131_165134_create_sys_dictionary"}
}
func (m *Migration20230131_165134CreateSysDictionary) ID() string {
return m.id
}
func (m *Migration20230131_165134CreateSysDictionary) Up(tx *gorm.DB) error {
table := m.table()
return tx.AutoMigrate(&table)
}
func (m *Migration20230131_165134CreateSysDictionary) Down(tx *gorm.DB) error {
return tx.Migrator().DropTable(m.table())
}
func (m *Migration20230131_165134CreateSysDictionary) table() interface{} {
type SysDictionary struct {
gorm.Model
Name string `gorm:"comment:字典名(中)"` // 字典名(中)
Alias string `gorm:"comment:字典名(英)"` // 字典名(英)
Status bool `gorm:"comment:状态"` // 状态
Description string `gorm:"comment:描述"` // 描述
}
return SysDictionary{}
}