Skip to content

Commit

Permalink
BED-4363 - Refactor: Remove in-app migration sync for pure stepwise m…
Browse files Browse the repository at this point in the history
…igrations (#772)
  • Loading branch information
mistahj67 authored Aug 22, 2024
1 parent 44c79e2 commit 514e1c8
Show file tree
Hide file tree
Showing 17 changed files with 149 additions and 552 deletions.
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

0 comments on commit 514e1c8

Please sign in to comment.