Skip to content

Commit

Permalink
copy over existing postgres binaries with major version specified
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Aug 21, 2023
1 parent 1e62e98 commit 44ed1e6
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions cmd/internal/database/postgres/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ var (
// Once the upgrade was made, any error condition will require to recover the database from backup.
func (db *Postgres) Upgrade() error {
start := time.Now()

err := db.copyPostgresBinaries()
if err != nil {
return err
}

// First check if there are data already present
pgVersionFile := path.Join(db.datadir, postgresVersionFile)
if _, err := os.Stat(pgVersionFile); errors.Is(err, fs.ErrNotExist) {
Expand Down Expand Up @@ -236,3 +242,31 @@ func (db *Postgres) getBindir(pgConfigCmd string) (string, error) {
}
return strings.TrimSpace(string(out)), nil
}

func (db *Postgres) copyPostgresBinaries() error {
bindir, err := db.getBindir(postgresConfigCmd)
if err != nil {
return err
}

version, err := db.getBinaryVersion(postgresConfigCmd)
if err != nil {
return err
}

pgbindir := path.Join(db.datadir, fmt.Sprintf("pg-bin-v%d", version))

err = os.RemoveAll(pgbindir)
if err != nil {
return fmt.Errorf("unable to remove old pgbindir %w", err)
}

copy := exec.Command("cp", "-a", bindir, pgbindir)
copy.Stdout = os.Stdout
copy.Stderr = os.Stderr
err = copy.Run()
if err != nil {
return fmt.Errorf("unable to copy pgbindir %w", err)
}
return nil
}

0 comments on commit 44ed1e6

Please sign in to comment.