Include support for PostgreSQL 17

This commit is contained in:
Luis Eduardo Jeréz Girón
2024-10-13 23:09:15 -06:00
parent d7612836e6
commit fb97464444
9 changed files with 85 additions and 44 deletions

View File

@@ -24,7 +24,8 @@ RUN apt update && apt install -y postgresql-common && \
apt update && apt install -y \
wget unzip tzdata git \
postgresql-client-13 postgresql-client-14 \
postgresql-client-15 postgresql-client-16 && \
postgresql-client-15 postgresql-client-16 \
postgresql-client-17 && \
rm -rf /var/lib/apt/lists/*
# Install downloadable binaries

View File

@@ -24,7 +24,8 @@ RUN apt update && apt install -y postgresql-common && \
apt update && apt install -y \
wget unzip tzdata git \
postgresql-client-13 postgresql-client-14 \
postgresql-client-15 postgresql-client-16 && \
postgresql-client-15 postgresql-client-16 \
postgresql-client-17 && \
rm -rf /var/lib/apt/lists/*
# Install downloadable binaries

View File

@@ -24,7 +24,8 @@ RUN apt update && apt install -y postgresql-common && \
apt update && apt install -y \
wget unzip tzdata git \
postgresql-client-13 postgresql-client-14 \
postgresql-client-15 postgresql-client-16 && \
postgresql-client-15 postgresql-client-16 \
postgresql-client-17 && \
rm -rf /var/lib/apt/lists/*
# Install downloadable binaries

View File

@@ -0,0 +1,15 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE databases
DROP CONSTRAINT IF EXISTS databases_pg_version_check,
ADD CONSTRAINT databases_pg_version_check
CHECK (pg_version IN ('13', '14', '15', '16', '17'));
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
ALTER TABLE databases
DROP CONSTRAINT IF EXISTS databases_pg_version_check,
ADD CONSTRAINT databases_pg_version_check
CHECK (pg_version IN ('13', '14', '15', '16'));
-- +goose StatementEnd

View File

@@ -21,34 +21,41 @@ import (
*/
type version struct {
version string
pgDump string
psql string
Version string
PGDump string
PSQL string
}
type PGVersion enum.Member[version]
var (
PG13 = PGVersion{version{
version: "13",
pgDump: "/usr/lib/postgresql/13/bin/pg_dump",
psql: "/usr/lib/postgresql/13/bin/psql",
Version: "13",
PGDump: "/usr/lib/postgresql/13/bin/pg_dump",
PSQL: "/usr/lib/postgresql/13/bin/psql",
}}
PG14 = PGVersion{version{
version: "14",
pgDump: "/usr/lib/postgresql/14/bin/pg_dump",
psql: "/usr/lib/postgresql/14/bin/psql",
Version: "14",
PGDump: "/usr/lib/postgresql/14/bin/pg_dump",
PSQL: "/usr/lib/postgresql/14/bin/psql",
}}
PG15 = PGVersion{version{
version: "15",
pgDump: "/usr/lib/postgresql/15/bin/pg_dump",
psql: "/usr/lib/postgresql/15/bin/psql",
Version: "15",
PGDump: "/usr/lib/postgresql/15/bin/pg_dump",
PSQL: "/usr/lib/postgresql/15/bin/psql",
}}
PG16 = PGVersion{version{
version: "16",
pgDump: "/usr/lib/postgresql/16/bin/pg_dump",
psql: "/usr/lib/postgresql/16/bin/psql",
Version: "16",
PGDump: "/usr/lib/postgresql/16/bin/pg_dump",
PSQL: "/usr/lib/postgresql/16/bin/psql",
}}
PG17 = PGVersion{version{
Version: "17",
PGDump: "/usr/lib/postgresql/17/bin/pg_dump",
PSQL: "/usr/lib/postgresql/17/bin/psql",
}}
PGVersions = []PGVersion{PG13, PG14, PG15, PG16, PG17}
)
type Client struct{}
@@ -69,6 +76,8 @@ func (Client) ParseVersion(version string) (PGVersion, error) {
return PG15, nil
case "16":
return PG16, nil
case "17":
return PG17, nil
default:
return PGVersion{}, fmt.Errorf("pg version not allowed: %s", version)
}
@@ -76,12 +85,12 @@ func (Client) ParseVersion(version string) (PGVersion, error) {
// Test tests the connection to the PostgreSQL database
func (Client) Test(version PGVersion, connString string) error {
cmd := exec.Command(version.Value.psql, connString, "-c", "SELECT 1;")
cmd := exec.Command(version.Value.PSQL, connString, "-c", "SELECT 1;")
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf(
"error running psql test v%s: %s",
version.Value.version, output,
version.Value.Version, output,
)
}
@@ -152,7 +161,7 @@ func (Client) Dump(
errorBuffer := &bytes.Buffer{}
reader, writer := io.Pipe()
cmd := exec.Command(version.Value.pgDump, args...)
cmd := exec.Command(version.Value.PGDump, args...)
cmd.Stdout = writer
cmd.Stderr = errorBuffer
@@ -161,7 +170,7 @@ func (Client) Dump(
if err := cmd.Run(); err != nil {
writer.CloseWithError(fmt.Errorf(
"error running pg_dump v%s: %s",
version.Value.version, errorBuffer.String(),
version.Value.Version, errorBuffer.String(),
))
}
}()
@@ -248,12 +257,12 @@ func (Client) RestoreZip(
return fmt.Errorf("dump.sql file not found in ZIP file: %s", zipPath)
}
cmd = exec.Command(version.Value.psql, connString, "-f", dumpPath)
cmd = exec.Command(version.Value.PSQL, connString, "-f", dumpPath)
output, err = cmd.CombinedOutput()
if err != nil {
return fmt.Errorf(
"error running psql v%s command: %s",
version.Value.version, output,
version.Value.Version, output,
)
}

View File

@@ -0,0 +1,25 @@
package component
import (
"database/sql"
"github.com/eduardolat/pgbackweb/internal/integration/postgres"
"github.com/maragudk/gomponents"
"github.com/maragudk/gomponents/html"
)
func PGVersionSelectOptions(selectedVersion sql.NullString) gomponents.Node {
return GMap(
postgres.PGVersions,
func(pgVersion postgres.PGVersion) gomponents.Node {
return html.Option(
html.Value(pgVersion.Value.Version),
gomponents.Textf("PostgreSQL %s", pgVersion.Value.Version),
gomponents.If(
selectedVersion.Valid && selectedVersion.String == pgVersion.Value.Version,
html.Selected(),
),
)
},
)
}

View File

@@ -1,6 +1,8 @@
package databases
import (
"database/sql"
lucide "github.com/eduardolat/gomponents-lucide"
"github.com/eduardolat/pgbackweb/internal/database/dbgen"
"github.com/eduardolat/pgbackweb/internal/validate"
@@ -77,10 +79,7 @@ func createDatabaseButton() gomponents.Node {
Required: true,
HelpText: "The version of the database",
Children: []gomponents.Node{
html.Option(html.Value("13"), gomponents.Text("PostgreSQL 13")),
html.Option(html.Value("14"), gomponents.Text("PostgreSQL 14")),
html.Option(html.Value("15"), gomponents.Text("PostgreSQL 15")),
html.Option(html.Value("16"), gomponents.Text("PostgreSQL 16")),
component.PGVersionSelectOptions(sql.NullString{}),
},
}),

View File

@@ -90,22 +90,10 @@ func editDatabaseButton(
Required: true,
HelpText: "The version of the database",
Children: []gomponents.Node{
html.Option(
gomponents.If(database.PgVersion == "13", html.Selected()),
html.Value("13"), gomponents.Text("PostgreSQL 13"),
),
html.Option(
gomponents.If(database.PgVersion == "14", html.Selected()),
html.Value("14"), gomponents.Text("PostgreSQL 14"),
),
html.Option(
gomponents.If(database.PgVersion == "15", html.Selected()),
html.Value("15"), gomponents.Text("PostgreSQL 15"),
),
html.Option(
gomponents.If(database.PgVersion == "16", html.Selected()),
html.Value("16"), gomponents.Text("PostgreSQL 16"),
),
component.PGVersionSelectOptions(sql.NullString{
Valid: true,
String: database.PgVersion,
}),
},
}),

View File

@@ -33,6 +33,8 @@ check_command "/usr/lib/postgresql/15/bin/psql --version" "PostgreSQL 15 psql"
check_command "/usr/lib/postgresql/15/bin/pg_dump --version" "PostgreSQL 15 pg_dump"
check_command "/usr/lib/postgresql/16/bin/psql --version" "PostgreSQL 16 psql"
check_command "/usr/lib/postgresql/16/bin/pg_dump --version" "PostgreSQL 16 pg_dump"
check_command "/usr/lib/postgresql/17/bin/psql --version" "PostgreSQL 17 psql"
check_command "/usr/lib/postgresql/17/bin/pg_dump --version" "PostgreSQL 17 pg_dump"
# Check software installed by downloading binaries
check_command "task --version" "task"