(sqlUser *sql.DB, directory string)
| 397 | } |
| 398 | |
| 399 | func (info InitInfo) executeSQLRefs(sqlUser *sql.DB, directory string) error { |
| 400 | if directory == "" { |
| 401 | return nil |
| 402 | } |
| 403 | |
| 404 | if err := fileutils.EnsureDirectoryExists(directory); err != nil { |
| 405 | return fmt.Errorf("could not find directory: %s, err: %w", directory, err) |
| 406 | } |
| 407 | |
| 408 | files, err := fileutils.GetDirectoryContent(directory) |
| 409 | if err != nil { |
| 410 | return fmt.Errorf("could not get directory content from: %s, err: %w", |
| 411 | directory, err) |
| 412 | } |
| 413 | |
| 414 | // Sorting ensures that we execute the files in the correct order. |
| 415 | // We generate the file names by appending a prefix with the number of execution during the volume generation. |
| 416 | sort.Strings(files) |
| 417 | |
| 418 | for _, file := range files { |
| 419 | sql, ioErr := fileutils.ReadFile(path.Join(directory, file)) |
| 420 | if ioErr != nil { |
| 421 | return fmt.Errorf("could not read file: %s, err; %w", file, err) |
| 422 | } |
| 423 | |
| 424 | if err = info.executeQueries(sqlUser, []string{string(sql)}); err != nil { |
| 425 | return fmt.Errorf("could not execute queries: %w", err) |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | return nil |
| 430 | } |
| 431 | |
| 432 | // executeQueries run the set of queries in the provided database connection |
| 433 | func (info InitInfo) executeQueries(sqlUser *sql.DB, queries []string) error { |
no test coverage detected