diff --git a/.flyctl/cmd/pg-failover/main.go b/.flyctl/cmd/pg-failover/main.go index 206ce07b..ddf78b3c 100644 --- a/.flyctl/cmd/pg-failover/main.go +++ b/.flyctl/cmd/pg-failover/main.go @@ -4,8 +4,8 @@ import ( "fmt" "time" - "github.com/fly-examples/postgres-ha/pkg/flypg/stolon" - "github.com/fly-examples/postgres-ha/pkg/util" + "github.com/fly-apps/postgres-ha/pkg/flypg/stolon" + "github.com/fly-apps/postgres-ha/pkg/util" ) func main() { diff --git a/.flyctl/cmd/pg-restart/main.go b/.flyctl/cmd/pg-restart/main.go index d9756692..84a57292 100644 --- a/.flyctl/cmd/pg-restart/main.go +++ b/.flyctl/cmd/pg-restart/main.go @@ -4,7 +4,7 @@ import ( "fmt" "os/exec" - "github.com/fly-examples/postgres-ha/pkg/util" + "github.com/fly-apps/postgres-ha/pkg/util" ) func main() { diff --git a/.flyctl/cmd/pg-role/main.go b/.flyctl/cmd/pg-role/main.go index f307be01..24cc9278 100644 --- a/.flyctl/cmd/pg-role/main.go +++ b/.flyctl/cmd/pg-role/main.go @@ -6,8 +6,8 @@ import ( "net/http" "strings" - "github.com/fly-examples/postgres-ha/pkg/privnet" - "github.com/fly-examples/postgres-ha/pkg/util" + "github.com/fly-apps/postgres-ha/pkg/privnet" + "github.com/fly-apps/postgres-ha/pkg/util" ) func main() { diff --git a/.flyctl/cmd/pg-settings/main.go b/.flyctl/cmd/pg-settings/main.go index fa3ec713..473d5fed 100644 --- a/.flyctl/cmd/pg-settings/main.go +++ b/.flyctl/cmd/pg-settings/main.go @@ -9,8 +9,8 @@ import ( "os" "strings" - "github.com/fly-examples/postgres-ha/pkg/flypg" - "github.com/fly-examples/postgres-ha/pkg/util" + "github.com/fly-apps/postgres-ha/pkg/flypg" + "github.com/fly-apps/postgres-ha/pkg/util" ) func main() { @@ -38,9 +38,9 @@ func main() { sValues := "'" + strings.Join(sList, "', '") + "'" - sql := fmt.Sprintf(`select - name, setting, vartype, min_val, max_val, enumvals, context, unit, short_desc, pending_restart - FROM pg_settings WHERE name IN (%s); + sql := fmt.Sprintf(`select + name, setting, vartype, min_val, max_val, enumvals, context, unit, short_desc, pending_restart + FROM pg_settings WHERE name IN (%s); `, sValues) rows, err := conn.Query(context.Background(), sql) diff --git a/.flyctl/cmd/stolonctl-run/main.go b/.flyctl/cmd/stolonctl-run/main.go index 346e7b92..764a193e 100644 --- a/.flyctl/cmd/stolonctl-run/main.go +++ b/.flyctl/cmd/stolonctl-run/main.go @@ -6,8 +6,8 @@ import ( "encoding/base64" - "github.com/fly-examples/postgres-ha/pkg/flypg/stolon" - "github.com/fly-examples/postgres-ha/pkg/util" + "github.com/fly-apps/postgres-ha/pkg/flypg/stolon" + "github.com/fly-apps/postgres-ha/pkg/util" "github.com/google/shlex" ) diff --git a/Dockerfile b/Dockerfile index 7c87cf67..54653955 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ARG VERSION=custom FROM golang:1.16 as flyutil ARG VERSION -WORKDIR /go/src/github.com/fly-examples/postgres-ha +WORKDIR /go/src/github.com/fly-apps/postgres-ha COPY . . RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/flyadmin ./cmd/flyadmin @@ -23,7 +23,7 @@ FROM flyio/stolon:327008e as stolon FROM wrouesnel/postgres_exporter:latest AS postgres_exporter FROM postgres:${PG_VERSION} -ARG VERSION +ARG VERSION ARG POSTGIS_MAJOR=3 ARG WALG_VERSION=2.0.0 diff --git a/Dockerfile-timescaledb b/Dockerfile-timescaledb index 48d04833..0d756996 100644 --- a/Dockerfile-timescaledb +++ b/Dockerfile-timescaledb @@ -4,7 +4,7 @@ ARG VERSION=custom FROM golang:1.16 as flyutil ARG VERSION -WORKDIR /go/src/github.com/fly-examples/postgres-ha +WORKDIR /go/src/github.com/fly-apps/postgres-ha COPY . . RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/flyadmin ./cmd/flyadmin @@ -23,7 +23,7 @@ FROM flyio/stolon:327008e as stolon FROM wrouesnel/postgres_exporter:latest AS postgres_exporter FROM postgres:${PG_VERSION} -ARG VERSION +ARG VERSION ARG POSTGIS_MAJOR=3 ARG WALG_VERSION=2.0.0 diff --git a/cmd/start/main.go b/cmd/start/main.go index 7d220f06..d16452c1 100644 --- a/cmd/start/main.go +++ b/cmd/start/main.go @@ -14,10 +14,10 @@ import ( "syscall" "time" - "github.com/fly-examples/postgres-ha/pkg/flypg" - "github.com/fly-examples/postgres-ha/pkg/flypg/admin" - "github.com/fly-examples/postgres-ha/pkg/flyunlock" - "github.com/fly-examples/postgres-ha/pkg/supervisor" + "github.com/fly-apps/postgres-ha/pkg/flypg" + "github.com/fly-apps/postgres-ha/pkg/flypg/admin" + "github.com/fly-apps/postgres-ha/pkg/flyunlock" + "github.com/fly-apps/postgres-ha/pkg/supervisor" "github.com/jackc/pgx/v4" ) diff --git a/go.mod b/go.mod index 9bf6df2d..5aa6944e 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/fly-examples/postgres-ha +module github.com/fly-apps/postgres-ha go 1.16 diff --git a/pkg/commands/admin.go b/pkg/commands/admin.go index 33c850d3..ca33875b 100644 --- a/pkg/commands/admin.go +++ b/pkg/commands/admin.go @@ -3,17 +3,18 @@ package commands import ( "encoding/json" "fmt" - "github.com/fly-examples/postgres-ha/pkg/flypg" - "github.com/pkg/errors" "io" "net/http" "os/exec" "time" - "github.com/fly-examples/postgres-ha/pkg/flypg/admin" - "github.com/fly-examples/postgres-ha/pkg/flypg/stolon" - "github.com/fly-examples/postgres-ha/pkg/render" - "github.com/fly-examples/postgres-ha/pkg/util" + "github.com/fly-apps/postgres-ha/pkg/flypg" + "github.com/pkg/errors" + + "github.com/fly-apps/postgres-ha/pkg/flypg/admin" + "github.com/fly-apps/postgres-ha/pkg/flypg/stolon" + "github.com/fly-apps/postgres-ha/pkg/render" + "github.com/fly-apps/postgres-ha/pkg/util" ) func handleFailoverTrigger(w http.ResponseWriter, r *http.Request) { diff --git a/pkg/commands/dbs.go b/pkg/commands/dbs.go index a0095459..99cf83b0 100644 --- a/pkg/commands/dbs.go +++ b/pkg/commands/dbs.go @@ -4,8 +4,8 @@ import ( "encoding/json" "net/http" - "github.com/fly-examples/postgres-ha/pkg/flypg/admin" - "github.com/fly-examples/postgres-ha/pkg/render" + "github.com/fly-apps/postgres-ha/pkg/flypg/admin" + "github.com/fly-apps/postgres-ha/pkg/render" "github.com/go-chi/chi/v5" ) diff --git a/pkg/commands/handler.go b/pkg/commands/handler.go index bbe2dd61..4c39ef27 100644 --- a/pkg/commands/handler.go +++ b/pkg/commands/handler.go @@ -4,8 +4,8 @@ import ( "context" "net/http" - "github.com/fly-examples/postgres-ha/pkg/flypg" - "github.com/fly-examples/postgres-ha/pkg/flypg/stolon" + "github.com/fly-apps/postgres-ha/pkg/flypg" + "github.com/fly-apps/postgres-ha/pkg/flypg/stolon" "github.com/go-chi/chi/v5" "github.com/jackc/pgx/v4" ) diff --git a/pkg/commands/users.go b/pkg/commands/users.go index 2d864b0b..47990bee 100644 --- a/pkg/commands/users.go +++ b/pkg/commands/users.go @@ -4,8 +4,8 @@ import ( "encoding/json" "net/http" - "github.com/fly-examples/postgres-ha/pkg/flypg/admin" - "github.com/fly-examples/postgres-ha/pkg/render" + "github.com/fly-apps/postgres-ha/pkg/flypg/admin" + "github.com/fly-apps/postgres-ha/pkg/render" "github.com/go-chi/chi/v5" ) diff --git a/pkg/flycheck/pg.go b/pkg/flycheck/pg.go index 97592026..266e3631 100644 --- a/pkg/flycheck/pg.go +++ b/pkg/flycheck/pg.go @@ -7,8 +7,8 @@ import ( "strings" "time" - "github.com/fly-examples/postgres-ha/pkg/flypg" - "github.com/fly-examples/postgres-ha/pkg/privnet" + "github.com/fly-apps/postgres-ha/pkg/flypg" + "github.com/fly-apps/postgres-ha/pkg/privnet" "github.com/pkg/errors" chk "github.com/superfly/fly-checks/check" diff --git a/pkg/flycheck/role.go b/pkg/flycheck/role.go index 27203f31..312b6f4d 100644 --- a/pkg/flycheck/role.go +++ b/pkg/flycheck/role.go @@ -3,10 +3,11 @@ package flycheck import ( "context" "fmt" + chk "github.com/superfly/fly-checks/check" - "github.com/fly-examples/postgres-ha/pkg/flypg" - "github.com/fly-examples/postgres-ha/pkg/flypg/admin" + "github.com/fly-apps/postgres-ha/pkg/flypg" + "github.com/fly-apps/postgres-ha/pkg/flypg/admin" "github.com/pkg/errors" ) diff --git a/pkg/flypg/admin/admin.go b/pkg/flypg/admin/admin.go index d47965fc..8dba2fe6 100644 --- a/pkg/flypg/admin/admin.go +++ b/pkg/flypg/admin/admin.go @@ -5,11 +5,12 @@ import ( "context" "crypto/md5" "fmt" - "github.com/pkg/errors" "os" "strings" - "github.com/fly-examples/postgres-ha/pkg/flypg" + "github.com/pkg/errors" + + "github.com/fly-apps/postgres-ha/pkg/flypg" "github.com/jackc/pgx/v4" ) @@ -60,8 +61,8 @@ func ChangePassword(ctx context.Context, pg *pgx.Conn, username, password string func ListDatabases(ctx context.Context, pg *pgx.Conn) ([]DbInfo, error) { sql := ` SELECT d.datname, - (SELECT array_agg(u.usename::text order by u.usename) - from pg_user u + (SELECT array_agg(u.usename::text order by u.usename) + from pg_user u where has_database_privilege(u.usename, d.datname, 'CONNECT')) as allowed_users from pg_database d where d.datistemplate = false order by d.datname; @@ -119,10 +120,10 @@ func ListUsers(ctx context.Context, pg *pgx.Conn) ([]UserInfo, error) { from pg_database d WHERE datistemplate = false AND has_database_privilege(u.usename, d.datname, 'CONNECT') - ) as + ) as allowed_databases - from - pg_user u join pg_authid a on u.usesysid = a.oid + from + pg_user u join pg_authid a on u.usesysid = a.oid order by u.usename ` @@ -147,20 +148,20 @@ func ListUsers(ctx context.Context, pg *pgx.Conn) ([]UserInfo, error) { func FindUser(ctx context.Context, pg *pgx.Conn, username string) (*UserInfo, error) { sql := ` - select + select u.usename, usesuper as superuser, userepl as repluser, a.rolpassword as passwordhash, ( - SELECT + SELECT array_agg(d.datname::text order by d.datname) from pg_database d WHERE datistemplate = false AND has_database_privilege(u.usename, d.datname, 'CONNECT') - ) AS + ) AS allowed_databases - FROM - pg_user u join pg_authid a on u.usesysid = a.oid + FROM + pg_user u join pg_authid a on u.usesysid = a.oid WHERE u.usename='%s';` sql = fmt.Sprintf(sql, username) @@ -211,9 +212,9 @@ func DeleteDatabase(ctx context.Context, pg *pgx.Conn, name string) error { func FindDatabase(ctx context.Context, pg *pgx.Conn, name string) (*DbInfo, error) { sql := ` - SELECT - datname, - (SELECT array_agg(u.usename::text order by u.usename) FROM pg_user u WHERE has_database_privilege(u.usename, d.datname, 'CONNECT')) as allowed_users + SELECT + datname, + (SELECT array_agg(u.usename::text order by u.usename) FROM pg_user u WHERE has_database_privilege(u.usename, d.datname, 'CONNECT')) as allowed_users FROM pg_database d WHERE d.datname='%s'; ` @@ -315,16 +316,16 @@ func ResolveSettings(ctx context.Context, pg *pgx.Conn, list []string) (*flypg.S sql := fmt.Sprintf(` SELECT - name, - setting, - vartype, - min_val, - max_val, - enumvals, - context, - unit, - short_desc, - pending_restart + name, + setting, + vartype, + min_val, + max_val, + enumvals, + context, + unit, + short_desc, + pending_restart FROM pg_settings WHERE name IN (%s);`, sValues) rows, err := pg.Query(ctx, sql) diff --git a/pkg/flypg/node.go b/pkg/flypg/node.go index b659658d..a8878f4d 100644 --- a/pkg/flypg/node.go +++ b/pkg/flypg/node.go @@ -10,7 +10,7 @@ import ( "strconv" "strings" - "github.com/fly-examples/postgres-ha/pkg/privnet" + "github.com/fly-apps/postgres-ha/pkg/privnet" "github.com/jackc/pgx/v4" "github.com/pkg/errors" ) diff --git a/pkg/flypg/stolon.go b/pkg/flypg/stolon.go index 3a6e75a3..cf0ddb9d 100644 --- a/pkg/flypg/stolon.go +++ b/pkg/flypg/stolon.go @@ -7,7 +7,7 @@ import ( "os/exec" "strings" - "github.com/fly-examples/postgres-ha/pkg/flypg/stolon" + "github.com/fly-apps/postgres-ha/pkg/flypg/stolon" "github.com/pkg/errors" ) diff --git a/pkg/flyunlock/unlock.go b/pkg/flyunlock/unlock.go index 977ae3b2..c07bfa09 100644 --- a/pkg/flyunlock/unlock.go +++ b/pkg/flyunlock/unlock.go @@ -11,9 +11,9 @@ import ( "strings" "time" - "github.com/fly-examples/postgres-ha/pkg/flypg/admin" - "github.com/fly-examples/postgres-ha/pkg/privnet" - "github.com/fly-examples/postgres-ha/pkg/supervisor" + "github.com/fly-apps/postgres-ha/pkg/flypg/admin" + "github.com/fly-apps/postgres-ha/pkg/privnet" + "github.com/fly-apps/postgres-ha/pkg/supervisor" "github.com/jackc/pgx/v4" "github.com/pkg/errors" ) diff --git a/pkg/server/http.go b/pkg/server/http.go index 6e431c4c..b0c3b7c8 100644 --- a/pkg/server/http.go +++ b/pkg/server/http.go @@ -4,8 +4,8 @@ import ( "fmt" "net/http" - "github.com/fly-examples/postgres-ha/pkg/commands" - "github.com/fly-examples/postgres-ha/pkg/flycheck" + "github.com/fly-apps/postgres-ha/pkg/commands" + "github.com/fly-apps/postgres-ha/pkg/flycheck" "github.com/go-chi/chi/v5" ) diff --git a/pkg/supervisor/supervisor.go b/pkg/supervisor/supervisor.go index 9c93327d..9c442359 100644 --- a/pkg/supervisor/supervisor.go +++ b/pkg/supervisor/supervisor.go @@ -9,7 +9,7 @@ import ( "syscall" "time" - "github.com/fly-examples/postgres-ha/pkg/server" + "github.com/fly-apps/postgres-ha/pkg/server" "github.com/google/shlex" "golang.org/x/sync/errgroup" ) diff --git a/pkg/util/env.go b/pkg/util/env.go index 237ca866..2a1d6efa 100644 --- a/pkg/util/env.go +++ b/pkg/util/env.go @@ -5,7 +5,7 @@ import ( "os" "path/filepath" - "github.com/fly-examples/postgres-ha/pkg/flypg" + "github.com/fly-apps/postgres-ha/pkg/flypg" ) func BuildEnv() ([]string, error) {