(sql string)
| 44 | } |
| 45 | |
| 46 | func parseRestoreSQL(sql string) (*RestoreConfig, error) { |
| 47 | matches := restoreRegex.FindStringSubmatch(sql) |
| 48 | if matches == nil { |
| 49 | // No match means the SQL doesn't follow the expected pattern |
| 50 | return nil, nil |
| 51 | } |
| 52 | |
| 53 | // matches: |
| 54 | // [1] DbName |
| 55 | // [2] RemoteUri |
| 56 | // [3] Endpoint |
| 57 | // [4] AccessKeyId |
| 58 | // [5] SecretAccessKey |
| 59 | dbName := strings.TrimSpace(matches[1]) |
| 60 | remoteUri := strings.TrimSpace(matches[2]) |
| 61 | endpoint := strings.TrimSpace(matches[3]) |
| 62 | accessKeyId := strings.TrimSpace(matches[4]) |
| 63 | secretAccessKey := strings.TrimSpace(matches[5]) |
| 64 | |
| 65 | if dbName == "" { |
| 66 | return nil, fmt.Errorf("missing required restore configuration: DATABASE") |
| 67 | } |
| 68 | if remoteUri == "" { |
| 69 | return nil, fmt.Errorf("missing required restore configuration: TO '<URI>'") |
| 70 | } |
| 71 | if endpoint == "" { |
| 72 | return nil, fmt.Errorf("missing required restore configuration: ENDPOINT") |
| 73 | } |
| 74 | if accessKeyId == "" { |
| 75 | return nil, fmt.Errorf("missing required restore configuration: ACCESS_KEY_ID") |
| 76 | } |
| 77 | if secretAccessKey == "" { |
| 78 | return nil, fmt.Errorf("missing required restore configuration: SECRET_ACCESS_KEY") |
| 79 | } |
| 80 | |
| 81 | storageConfig, remotePath, err := storage.ConstructStorageConfig(remoteUri, endpoint, accessKeyId, secretAccessKey) |
| 82 | if err != nil { |
| 83 | return nil, fmt.Errorf("failed to construct storage configuration for restore: %w", err) |
| 84 | } |
| 85 | |
| 86 | return NewRestoreConfig(dbName, remotePath, storageConfig), nil |
| 87 | } |
| 88 | |
| 89 | func (h *ConnectionHandler) executeRestore(restoreConfig *RestoreConfig) (string, error) { |
| 90 | provider := h.server.Provider |
no test coverage detected