1599190683659_tables.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package version
  2. import (
  3. "github.com/go-admin-team/go-admin-core/sdk/config"
  4. "runtime"
  5. "go-admin/cmd/migrate/migration"
  6. "go-admin/cmd/migrate/migration/models"
  7. common "go-admin/common/models"
  8. "gorm.io/gorm"
  9. )
  10. func init() {
  11. _, fileName, _, _ := runtime.Caller(0)
  12. migration.Migrate.SetVersion(migration.GetFilename(fileName), _1599190683659Tables)
  13. }
  14. func _1599190683659Tables(db *gorm.DB, version string) error {
  15. return db.Transaction(func(tx *gorm.DB) error {
  16. if config.DatabaseConfig.Driver == "mysql" {
  17. tx = tx.Set("gorm:table_options", "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4")
  18. }
  19. err := tx.Migrator().AutoMigrate(
  20. new(models.SysDept),
  21. new(models.SysConfig),
  22. new(models.SysTables),
  23. new(models.SysColumns),
  24. new(models.SysMenu),
  25. new(models.SysLoginLog),
  26. new(models.SysOperaLog),
  27. new(models.SysRoleDept),
  28. new(models.SysUser),
  29. new(models.SysRole),
  30. new(models.SysPost),
  31. new(models.DictData),
  32. new(models.DictType),
  33. new(models.SysJob),
  34. new(models.SysConfig),
  35. new(models.SysApi),
  36. new(models.TbDemo),
  37. )
  38. if err != nil {
  39. return err
  40. }
  41. if err := models.InitDb(tx); err != nil {
  42. return err
  43. }
  44. return tx.Create(&common.Migration{
  45. Version: version,
  46. }).Error
  47. })
  48. }