feat: live module and jenkins pipeline to harbor deploy
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
package recharge
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"kra/internal/data/ledger"
|
||||
"kra/pkg/database/migration"
|
||||
)
|
||||
|
||||
// rechargeOrderV1 freezes the original schema owned by the first migration.
|
||||
type rechargeOrderV1 struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
OrderNo string `gorm:"size:80;uniqueIndex"`
|
||||
UserID uint `gorm:"index"`
|
||||
Diamonds int64
|
||||
AmountCents int64
|
||||
RateCents int64
|
||||
PaymentMethod string `gorm:"size:40;index"`
|
||||
Status string `gorm:"size:30;index"`
|
||||
CreatedAt time.Time `gorm:"index"`
|
||||
UpdatedAt time.Time
|
||||
CompletedAt *time.Time
|
||||
}
|
||||
|
||||
func (rechargeOrderV1) TableName() string { return "live_recharge_orders" }
|
||||
|
||||
func Migrations() []migration.Step {
|
||||
return []migration.Step{{ID: "202609190003_recharge_schema", Migrate: func(db *gorm.DB) error {
|
||||
if err := migration.CreateMissingTables(db, &ledger.RechargePlanPO{}, &rechargeOrderV1{}); err != nil {
|
||||
return err
|
||||
}
|
||||
var n int64
|
||||
if err := db.Model(&ledger.RechargePlanPO{}).Count(&n).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if n > 0 {
|
||||
return nil
|
||||
}
|
||||
return db.Create(&[]ledger.RechargePlanPO{{Sort: 1, Diamonds: 60, AmountCents: 600, Enabled: true}, {Sort: 2, Diamonds: 300, AmountCents: 3000, Enabled: true}, {Sort: 3, Diamonds: 980, AmountCents: 9800, Enabled: true}, {Sort: 4, Diamonds: 1980, AmountCents: 19800, Enabled: true}, {Sort: 5, Diamonds: 3280, AmountCents: 32800, Enabled: true}, {Sort: 6, Diamonds: 6980, AmountCents: 69800, Enabled: true}}).Error
|
||||
}}, {ID: "202609190007_recharge_payment_unification", Migrate: func(db *gorm.DB) error {
|
||||
migrator := db.Migrator()
|
||||
if !migrator.HasColumn(&ledger.RechargeOrderPO{}, "CreditedAt") {
|
||||
if err := migrator.AddColumn(&ledger.RechargeOrderPO{}, "CreditedAt"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, column := range []string{"payment_method", "status", "completed_at"} {
|
||||
if migrator.HasColumn(&rechargeOrderV1{}, column) {
|
||||
if err := migrator.DropColumn(&rechargeOrderV1{}, column); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}}}
|
||||
}
|
||||
Reference in New Issue
Block a user