2025_07_21_091558_add_links_table.go 680 B

12345678910111213141516171819202122232425262728293031
  1. package migrations
  2. import (
  3. "gorm.io/gorm"
  4. "github.com/runningwater/gohub/app/models"
  5. "github.com/runningwater/gohub/pkg/migrate"
  6. )
  7. func init() {
  8. type Link struct {
  9. models.BaseModel
  10. Name string `gorm:"type:varchar(255);not null"`
  11. URL string `gorm:"type:varchar(255);default:null"`
  12. models.CommonTimestampsField
  13. }
  14. up := func(migrator gorm.Migrator, DB *gorm.DB) {
  15. _ = DB.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci comment='友情链接'").AutoMigrate(&Link{})
  16. }
  17. down := func(migrator gorm.Migrator, DB *gorm.DB) {
  18. _ = migrator.DropTable(&Link{})
  19. }
  20. migrate.Add(up, down, "2025_07_21_091558_add_links_table")
  21. }