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

BED-4363 - Refactor: Remove in-app migration sync for pure stepwise migrations #772

Merged
merged 7 commits into from
Aug 22, 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
1 change: 1 addition & 0 deletions cmd/api/src/auth/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (s PermissionSet) All() model.Permissions {
}
}

// Permissions Note: Not the only source of truth, changes here must be added to a migration *.sql file to update the permissions table
func Permissions() PermissionSet {
return PermissionSet{
AppReadApplicationConfiguration: model.NewPermission("app", "ReadAppConfig"),
Expand Down
30 changes: 1 addition & 29 deletions cmd/api/src/auth/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package auth

import (
"fmt"

"github.com/specterops/bloodhound/src/model"
)

Expand All @@ -36,33 +34,7 @@ type RoleTemplate struct {
Permissions model.Permissions
}

func (s RoleTemplate) Build(allPermissions model.Permissions) (model.Role, error) {
role := model.Role{
Name: s.Name,
Description: s.Description,
Permissions: make(model.Permissions, len(s.Permissions)),
}

for idx, requiredPermission := range s.Permissions {
found := false

for _, permission := range allPermissions {
if permission.Equals(requiredPermission) {
role.Permissions[idx] = permission
found = true

break
}
}

if !found {
return role, fmt.Errorf("unable to locate required permission %s for role template %s", requiredPermission, s.Name)
}
}

return role, nil
}

// Roles Note: Not the source of truth, changes here must be added to a migration *.sql file to update the roles & roles_permissions table
func Roles() map[string]RoleTemplate {
permissions := Permissions()

Expand Down
7 changes: 1 addition & 6 deletions cmd/api/src/database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ type Database interface {

Wipe(ctx context.Context) error
Migrate(ctx context.Context) error
RequiresMigration(ctx context.Context) (bool, error)
CreateInstallation(ctx context.Context) (model.Installation, error)
GetInstallation(ctx context.Context) (model.Installation, error)
HasInstallation(ctx context.Context) (bool, error)
Expand Down Expand Up @@ -241,13 +240,9 @@ func (s *BloodhoundDB) Wipe(ctx context.Context) error {
})
}

func (s *BloodhoundDB) RequiresMigration(ctx context.Context) (bool, error) {
return migration.NewMigrator(s.db.WithContext(ctx)).RequiresMigration()
}

func (s *BloodhoundDB) Migrate(ctx context.Context) error {
// Run the migrator
if err := migration.NewMigrator(s.db.WithContext(ctx)).Migrate(); err != nil {
if err := migration.NewMigrator(s.db.WithContext(ctx)).ExecuteStepwiseMigrations(); err != nil {
log.Errorf("Error during SQL database migration phase: %v", err)
return err
}
Expand Down
102 changes: 0 additions & 102 deletions cmd/api/src/database/migration/agi.go

This file was deleted.

29 changes: 0 additions & 29 deletions cmd/api/src/database/migration/agi_test.go

This file was deleted.

77 changes: 0 additions & 77 deletions cmd/api/src/database/migration/app_config.go

This file was deleted.

Loading
Loading