UpdateInstanceProfiles updates the profiles of an instance in the order they are given.
(ctx context.Context, tx *sql.Tx, instanceID int, projectName string, profiles []string)
| 40 | |
| 41 | // UpdateInstanceProfiles updates the profiles of an instance in the order they are given. |
| 42 | func UpdateInstanceProfiles(ctx context.Context, tx *sql.Tx, instanceID int, projectName string, profiles []string) error { |
| 43 | err := DeleteInstanceProfiles(ctx, tx, instanceID) |
| 44 | if err != nil { |
| 45 | return err |
| 46 | } |
| 47 | |
| 48 | project := projectName |
| 49 | enabled, err := ProjectHasProfiles(ctx, tx, project) |
| 50 | if err != nil { |
| 51 | return fmt.Errorf("Check if project has profiles: %w", err) |
| 52 | } |
| 53 | |
| 54 | if !enabled { |
| 55 | project = "default" |
| 56 | } |
| 57 | |
| 58 | applyOrder := 1 |
| 59 | stmt, err := Stmt(tx, instanceProfileCreate) |
| 60 | if err != nil { |
| 61 | return fmt.Errorf("Failed to get \"instanceProfileCreate\" prepared statement: %w", err) |
| 62 | } |
| 63 | |
| 64 | for _, name := range profiles { |
| 65 | profileID, err := GetProfileID(ctx, tx, project, name) |
| 66 | if err != nil { |
| 67 | return err |
| 68 | } |
| 69 | |
| 70 | _, err = stmt.Exec(instanceID, profileID, applyOrder) |
| 71 | if err != nil { |
| 72 | return err |
| 73 | } |
| 74 | |
| 75 | applyOrder = applyOrder + 1 |
| 76 | } |
| 77 | |
| 78 | return nil |
| 79 | } |
searching dependent graphs…