diff --git a/database/db.go b/database/db.go index d739f6ea..300a73c0 100644 --- a/database/db.go +++ b/database/db.go @@ -26,35 +26,20 @@ const ( ) func initModels() error { - // Order matters: first create tables without dependencies - baseModels := []interface{}{ + models := []interface{}{ &model.User{}, - &model.Setting{}, - } - - // Migrate base models - for _, model := range baseModels { - if err := db.AutoMigrate(model); err != nil { - log.Printf("Error auto migrating base model: %v", err) - return err - } - } - - // Then migrate models with dependencies - dependentModels := []interface{}{ &model.Inbound{}, &model.OutboundTraffics{}, + &model.Setting{}, &model.InboundClientIps{}, &xray.ClientTraffic{}, } - - for _, model := range dependentModels { + for _, model := range models { if err := db.AutoMigrate(model); err != nil { - log.Printf("Error auto migrating dependent model: %v", err) + log.Printf("Error auto migrating model: %v", err) return err } } - return nil } diff --git a/database/model/model.go b/database/model/model.go index 915cae0b..e9d1836f 100644 --- a/database/model/model.go +++ b/database/model/model.go @@ -29,14 +29,14 @@ type User struct { type Inbound struct { Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"` - UserId int `json:"-" gorm:"index"` + UserId int `json:"-"` Up int64 `json:"up" form:"up"` Down int64 `json:"down" form:"down"` Total int64 `json:"total" form:"total"` Remark string `json:"remark" form:"remark"` Enable bool `json:"enable" form:"enable"` ExpiryTime int64 `json:"expiryTime" form:"expiryTime"` - ClientStats []xray.ClientTraffic `gorm:"foreignKey:InboundId;references:Id;constraint:OnDelete:CASCADE" json:"clientStats"` + ClientStats []xray.ClientTraffic `gorm:"foreignKey:InboundId;references:Id" json:"clientStats" form:"clientStats"` // config part Listen string `json:"listen" form:"listen"` diff --git a/install.sh b/install.sh index f5ce9b96..150ae86c 100644 --- a/install.sh +++ b/install.sh @@ -283,4 +283,4 @@ install_x-ui() { echo -e "${green}Running...${plain}" install_base -install_x-ui $1 \ No newline at end of file +install_x-ui $1 diff --git a/x-ui.sh b/x-ui.sh index 7e8cbfda..4f2e57d8 100644 --- a/x-ui.sh +++ b/x-ui.sh @@ -1912,4 +1912,4 @@ if [[ $# > 0 ]]; then esac else show_menu -fi \ No newline at end of file +fi diff --git a/xray/client_traffic.go b/xray/client_traffic.go index 6eb2d270..0f2389a0 100644 --- a/xray/client_traffic.go +++ b/xray/client_traffic.go @@ -2,9 +2,9 @@ package xray type ClientTraffic struct { Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"` - InboundId int `json:"inboundId" form:"inboundId" gorm:"index;not null"` + InboundId int `json:"inboundId" form:"inboundId"` Enable bool `json:"enable" form:"enable"` - Email string `json:"email" form:"email" gorm:"uniqueIndex"` + Email string `json:"email" form:"email" gorm:"unique"` Up int64 `json:"up" form:"up"` Down int64 `json:"down" form:"down"` ExpiryTime int64 `json:"expiryTime" form:"expiryTime"`