Skip to content

Commit

Permalink
pgpool. manually set search_path (schema parameter)
Browse files Browse the repository at this point in the history
  • Loading branch information
absorbb committed Dec 30, 2023
1 parent ea9b0d8 commit 772ef26
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
5 changes: 5 additions & 0 deletions jitsubase/pg/pgpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pg
import (
"context"
"fmt"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
"regexp"
)
Expand All @@ -27,6 +28,10 @@ func NewPGPool(url string) (*pgxpool.Pool, error) {
if schema != "" {
pgCfg.ConnConfig.RuntimeParams["search_path"] = schema
}
pgCfg.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
_, err := conn.Exec(ctx, fmt.Sprintf("SET search_path TO '%s'", schema))
return err
}
dbpool, err := pgxpool.NewWithConfig(context.Background(), pgCfg)
if err != nil {
return nil, fmt.Errorf("Unable to create postgres connection pool: %v\n", err)
Expand Down
22 changes: 12 additions & 10 deletions sidecar.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ FROM golang:1.21.5-alpine as build
RUN mkdir /app
WORKDIR /app

COPY sync-sidecar/go.mod .
COPY sync-sidecar/go.sum .
RUN mkdir jitsubase sync-sidecar

RUN go mod download
COPY jitsubase/go.* ./jitsubase/
COPY sync-sidecar/go.* ./sync-sidecar/

RUN go work init jitsubase sync-sidecar

# go mod download applied changes to go.sum that we don't want to override
RUN mv go.sum go.sum_
WORKDIR /app/sync-sidecar

COPY sync-sidecar/. .
RUN go mod download

WORKDIR /app

# restore modified go.sum
RUN mv go.sum_ go.sum
COPY . .

# Build bulker
RUN go build -o sidecar
RUN go build -o sidecar ./sync-sidecar

#######################################
# FINAL STAGE
Expand All @@ -30,6 +32,6 @@ RUN mkdir /app
WORKDIR /app

# Copy bulkerapp
COPY --from=build /app/sidecar ./sidecar
COPY --from=build /app/sidecar ./

CMD ["/app/sidecar"]

0 comments on commit 772ef26

Please sign in to comment.