From fab0cdf407db8f378f11c67bf09c7cee19d693e0 Mon Sep 17 00:00:00 2001 From: donggyu Date: Thu, 2 May 2024 16:33:35 +0900 Subject: [PATCH] bugfix. fix ordering of auto migration --- internal/database/database.go | 15 +++++++++++---- internal/model/permission-endpoint.go | 4 ++++ internal/model/permission.go | 2 -- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/internal/database/database.go b/internal/database/database.go index 44f7f095..23c04070 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -63,7 +63,6 @@ func migrateSchema(db *gorm.DB) error { if err := db.AutoMigrate(&model.CacheEmailCode{}, &model.ExpiredTokenTime{}, &model.Role{}, - &model.PermissionEndpoint{}, &model.CloudAccount{}, &model.StackTemplate{}, &model.Organization{}, @@ -78,10 +77,8 @@ func migrateSchema(db *gorm.DB) error { &model.SystemNotificationAction{}, &model.SystemNotificationMetricParameter{}, &model.SystemNotificationTemplate{}, - &model.SystemNotificationCondition{}, &model.SystemNotificationRule{}, - &model.Permission{}, - &model.Endpoint{}, + &model.SystemNotificationCondition{}, &model.Project{}, &model.ProjectMember{}, &model.ProjectNamespace{}, @@ -94,6 +91,16 @@ func migrateSchema(db *gorm.DB) error { ); err != nil { return err } + + if err := db.AutoMigrate(&model.Permission{}); err != nil { + return err + } + if err := db.AutoMigrate(&model.Endpoint{}); err != nil { + return err + } + if err := db.AutoMigrate(&model.PermissionEndpoint{}); err != nil { + return err + } return nil } diff --git a/internal/model/permission-endpoint.go b/internal/model/permission-endpoint.go index b7fe0653..10fc3d4f 100644 --- a/internal/model/permission-endpoint.go +++ b/internal/model/permission-endpoint.go @@ -14,6 +14,10 @@ type PermissionEndpoint struct { Endpoint Endpoint `gorm:"foreignKey:EndpointName;references:Name"` } +func (PermissionEndpoint) TableName() string { + return "permission_endpoints" +} + var ( // map[EdgeKey][]Endpoints edgeKeyEndpointMap = map[string][]Endpoint{ diff --git a/internal/model/permission.go b/internal/model/permission.go index a84fa777..0e17b7e8 100644 --- a/internal/model/permission.go +++ b/internal/model/permission.go @@ -68,8 +68,6 @@ type Permission struct { RoleID *string `json:"role_id,omitempty"` Role *Role `gorm:"foreignKey:RoleID;references:ID;" json:"role,omitempty"` Endpoints []*Endpoint `gorm:"many2many:permission_endpoints;joinForeignKey:EdgeKey;joinReferences:EndpointName;" json:"endpoints,omitempty"` - //PermissionEndpoint []*PermissionEndpoint `gorm:"foreignKey:EdgeKey;references:EdgeKey;"` - // omit empty ParentID *uuid.UUID `json:"parent_id,omitempty"` Parent *Permission `gorm:"foreignKey:ParentID;references:ID;" json:"parent,omitempty"`