Skip to content

Commit

Permalink
Merge pull request #463 from cho4036/authorization_endpoint
Browse files Browse the repository at this point in the history
bugfix. fix ordering of auto migration
  • Loading branch information
ktkfree authored May 2, 2024
2 parents 9347811 + fab0cdf commit 2a967cc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
15 changes: 11 additions & 4 deletions internal/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand All @@ -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{},
Expand All @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions internal/model/permission-endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 0 additions & 2 deletions internal/model/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 2a967cc

Please sign in to comment.