Update integration package to use postgres instead of pgdump

This commit is contained in:
Luis Eduardo Jeréz Girón
2024-08-02 12:09:59 -06:00
parent 7e0d6db929
commit c992dfd8f2
4 changed files with 22 additions and 14 deletions

View File

@@ -1,21 +1,21 @@
package integration
import (
"github.com/eduardolat/pgbackweb/internal/integration/pgdump"
"github.com/eduardolat/pgbackweb/internal/integration/postgres"
"github.com/eduardolat/pgbackweb/internal/integration/s3"
)
type Integration struct {
PGDumpClient *pgdump.Client
S3Client *s3.Client
PGClient *postgres.Client
S3Client *s3.Client
}
func New() *Integration {
pgdumpClient := pgdump.New()
pgClient := postgres.New()
s3Client := s3.New()
return &Integration{
PGDumpClient: pgdumpClient,
S3Client: s3Client,
PGClient: pgClient,
S3Client: s3Client,
}
}

View File

@@ -1,4 +1,4 @@
package pgdump
package postgres
import (
"fmt"
@@ -8,6 +8,14 @@ import (
"github.com/orsinium-labs/enum"
)
/*
Important:
Versions supported by PG Back Web must be supported in PostgreSQL Version Policy
https://www.postgresql.org/support/versioning/
Backing up a database from an old unsupported version should not be allowed.
*/
type version struct {
version string
pgDump string

View File

@@ -8,12 +8,12 @@ import (
func (s *Service) TestDatabase(
ctx context.Context, version, connString string,
) error {
pgVersion, err := s.ints.PGDumpClient.ParseVersion(version)
pgVersion, err := s.ints.PGClient.ParseVersion(version)
if err != nil {
return fmt.Errorf("error parsing PostgreSQL version: %w", err)
}
err = s.ints.PGDumpClient.Ping(pgVersion, connString)
err = s.ints.PGClient.Ping(pgVersion, connString)
if err != nil {
return fmt.Errorf("error pinging database: %w", err)
}

View File

@@ -7,7 +7,7 @@ import (
"time"
"github.com/eduardolat/pgbackweb/internal/database/dbgen"
"github.com/eduardolat/pgbackweb/internal/integration/pgdump"
"github.com/eduardolat/pgbackweb/internal/integration/postgres"
"github.com/eduardolat/pgbackweb/internal/logger"
"github.com/eduardolat/pgbackweb/internal/util/strutil"
"github.com/eduardolat/pgbackweb/internal/util/timeutil"
@@ -64,7 +64,7 @@ func (s *Service) RunExecution(ctx context.Context, backupID uuid.UUID) error {
})
}
pgVersion, err := s.ints.PGDumpClient.ParseVersion(back.DatabasePgVersion)
pgVersion, err := s.ints.PGClient.ParseVersion(back.DatabasePgVersion)
if err != nil {
logError(err)
return updateExec(dbgen.ExecutionsServiceUpdateExecutionParams{
@@ -75,7 +75,7 @@ func (s *Service) RunExecution(ctx context.Context, backupID uuid.UUID) error {
})
}
err = s.ints.PGDumpClient.Ping(pgVersion, back.DecryptedDatabaseConnectionString)
err = s.ints.PGClient.Ping(pgVersion, back.DecryptedDatabaseConnectionString)
if err != nil {
logError(err)
return updateExec(dbgen.ExecutionsServiceUpdateExecutionParams{
@@ -86,8 +86,8 @@ func (s *Service) RunExecution(ctx context.Context, backupID uuid.UUID) error {
})
}
dumpBytes, err := s.ints.PGDumpClient.DumpZip(
pgVersion, back.DecryptedDatabaseConnectionString, pgdump.DumpParams{
dumpBytes, err := s.ints.PGClient.DumpZip(
pgVersion, back.DecryptedDatabaseConnectionString, postgres.DumpParams{
DataOnly: back.BackupOptDataOnly,
SchemaOnly: back.BackupOptSchemaOnly,
Clean: back.BackupOptClean,