Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix. fix ordering of auto migration #463

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading