MCPcopy Index your code
hub / github.com/cloudnative-pg/cloudnative-pg / executeSQLRefs

Method executeSQLRefs

pkg/management/postgres/initdb.go:399–430  ·  view source on GitHub ↗
(sqlUser *sql.DB, directory string)

Source from the content-addressed store, hash-verified

397}
398
399func (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
433func (info InitInfo) executeQueries(sqlUser *sql.DB, queries []string) error {

Callers 1

ConfigureNewInstanceMethod · 0.95

Calls 2

executeQueriesMethod · 0.95
JoinMethod · 0.80

Tested by

no test coverage detected