mirror of
https://github.com/h44z/wg-portal
synced 2025-02-26 05:49:14 +00:00
fix foreign key problem (#23)
This commit is contained in:
parent
d165fc0658
commit
92d09535bc
@ -63,8 +63,7 @@ func init() {
|
|||||||
//
|
//
|
||||||
|
|
||||||
type Peer struct {
|
type Peer struct {
|
||||||
Peer *wgtypes.Peer `gorm:"-" json:"-"` // WireGuard peer
|
Peer *wgtypes.Peer `gorm:"-" json:"-"` // WireGuard peer
|
||||||
Device *Device `gorm:"foreignKey:DeviceName" binding:"-" json:"-"` // linked WireGuard device
|
|
||||||
Config string `gorm:"-" json:"-"`
|
Config string `gorm:"-" json:"-"`
|
||||||
|
|
||||||
UID string `form:"uid" binding:"required,alphanum" json:"-"` // uid for html identification
|
UID string `form:"uid" binding:"required,alphanum" json:"-"` // uid for html identification
|
||||||
@ -236,6 +235,7 @@ const (
|
|||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
Interface *wgtypes.Device `gorm:"-" json:"-"`
|
Interface *wgtypes.Device `gorm:"-" json:"-"`
|
||||||
|
Peers []Peer `gorm:"foreignKey:DeviceName" binding:"-" json:"-"` // linked WireGuard peers
|
||||||
|
|
||||||
Type DeviceType `form:"devicetype" binding:"required,oneof=client server"`
|
Type DeviceType `form:"devicetype" binding:"required,oneof=client server"`
|
||||||
DeviceName string `form:"device" gorm:"primaryKey" binding:"required,alphanum"`
|
DeviceName string `form:"device" gorm:"primaryKey" binding:"required,alphanum"`
|
||||||
@ -375,7 +375,7 @@ func NewPeerManager(db *gorm.DB, wg *Manager) (*PeerManager, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pm.db.AutoMigrate(&Peer{}, &Device{}); err != nil {
|
if err := pm.db.AutoMigrate(&Device{}, &Peer{}); err != nil {
|
||||||
return nil, errors.WithMessage(err, "failed to migrate peer database")
|
return nil, errors.WithMessage(err, "failed to migrate peer database")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user