migration.go 788 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package db
  2. import (
  3. "go.uber.org/zap"
  4. "cold-delivery/app/admin/model"
  5. jobModel "cold-delivery/app/jobs/model"
  6. )
  7. // 执行数据迁移
  8. func AutoMigrateDB() {
  9. //自动迁移模式
  10. err := DB.Set("gorm:table_options", "charset=utf8mb4").
  11. AutoMigrate(
  12. &jobModel.SysJob{},
  13. &model.SysUser{},
  14. //&model.SysRole{},
  15. //&model.SysRoleMenu{},
  16. //&model.SysMenu{},
  17. &model.SysDept{},
  18. &model.SysLoginLog{},
  19. &model.SysOperaLog{},
  20. &model.Address{},
  21. &model.AddressDefault{},
  22. &model.CoolerBox{},
  23. &model.Waybill{},
  24. &model.WaybillLogistics{},
  25. &model.WaybillTask{},
  26. &model.IceRaft{},
  27. &model.IceLocker{},
  28. &model.IceRaftRecord{},
  29. &model.CoolerBoxRecord{},
  30. &model.Drug{},
  31. )
  32. if err != nil {
  33. zap.L().Panic("migrate db fail", zap.Error(err))
  34. }
  35. }