指尖上的记忆指尖上的记忆
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub

gorm数据库迁移上:

	//简单数据库迁移,这个是比较简单的迁移操作(单表迁移)
	type Order struct {
		Id             uint      `gorm:"primarykey;not null;auto_increment;column:id;comment:ID"`
		No             string    `gorm:"type:varchar(255);default:NULL;column:no;comment:订单编号"`
		OutTradeNo     string    `gorm:"type:varchar(255);default:NULL;column:out_trade_no;comment:订单流水号"`
		PayOrderNo     string    `gorm:"type:varchar(255);default:NULL;column:pay_order_no;comment:支付平台订单号"`
		Title          string    `gorm:"type:varchar(255);default:NULL;column:title;comment:订单标题"`
		Amount         float64   `gorm:"type:decimal(10,2);default:0.0;column:amount;comment:订单金额"`
		Status         int8      `gorm:"type:tinyint(1);default:0;column:status;comment:订单状态[0:未支付,1:已完成,-1:已过期]"`
		PayAmount      float64   `gorm:"type:decimal(10,2);default:0.0;column:pay_amount;comment:支付金额"`
		PayStatus      int8      `gorm:"type:tinyint(1);default:0;column:pay_status;comment:支付状态[0:未支付,1:已支付,-1:支付失败]"`
		PayExpiredAt   time.Time `gorm:"type:timestamp;default:NULL;column:pay_expired_at;comment:支付过期时间"`
		PayAt          time.Time `gorm:"type:timestamp;default:NULL;column:pay_at;comment:支付过期时间"`
		UserId         int       `gorm:"type:int;default:NULL;column:user_id;comment:用户ID"`
		CreatedAt      time.Time `gorm:"type:timestamp;default:NULL;column:created_at;comment:创建时间"`
		DeletedAt      time.Time `gorm:"type:timestamp;default:NULL;column:deleted_at;comment:创建时间"`
		UpdatedAt      time.Time `gorm:"type:timestamp;default:NULL;column:updated_at;comment:更新时间"`
		CreatedAdminId int       `gorm:"type:int;default:NULL;column:created_admin_id;comment:创建人ID"`
		UpdatedAdminId int       `gorm:"type:int;default:NULL;column:updated_admin_id;comment:更新人ID"`
	}
	//err := common.Db.AutoMigrate(&model.Order{})
	//if err != nil {
	//	fmt.Println("迁移错误:", err)
	//}
	//
	//fmt.Println("迁移完成")

	//手动通过 Migrator 对象实现相关的操作
	//m := common.Db.Migrator()
	//err := m.CreateTable(&model.Order{})
	//if err != nil {
	//	fmt.Println("迁移错误:", err)
	//}
	//
	//fmt.Println("迁移完成")