You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.2 KiB

3 years ago
3 years ago
3 years ago
  1. package source
  2. import (
  3. "time"
  4. "github.com/flipped-aurora/gin-vue-admin/server/global"
  5. "github.com/flipped-aurora/gin-vue-admin/server/model/example"
  6. "github.com/gookit/color"
  7. "gorm.io/gorm"
  8. )
  9. var File = new(file)
  10. type file struct{}
  11. var files = []example.ExaFileUploadAndDownload{
  12. {global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "10.png", "https://qmplusimg.henrongyi.top/gvalogo.png", "png", "158787308910.png"},
  13. {global.GVA_MODEL{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "logo.png", "https://qmplusimg.henrongyi.top/1576554439myAvatar.png", "png", "1587973709logo.png"},
  14. }
  15. //@author: [SliverHorn](https://github.com/SliverHorn)
  16. //@description: exa_file_upload_and_downloads 表初始化数据
  17. func (f *file) Init() error {
  18. return global.GVA_DB.Transaction(func(tx *gorm.DB) error {
  19. if tx.Where("id IN ?", []int{1, 2}).Find(&[]example.ExaFileUploadAndDownload{}).RowsAffected == 2 {
  20. color.Danger.Println("\n[Mysql] --> exa_file_upload_and_downloads 表初始数据已存在!")
  21. return nil
  22. }
  23. if err := tx.Create(&files).Error; err != nil { // 遇到错误时回滚事务
  24. return err
  25. }
  26. color.Info.Println("\n[Mysql] --> exa_file_upload_and_downloads 表初始数据成功!")
  27. return nil
  28. })
  29. }