Skip to content

Commit

Permalink
Postgres fixes (#372)
Browse files Browse the repository at this point in the history
* Fix chinook

* Fix chinook

* fix perms

* fix perms
  • Loading branch information
EnigmaCurry authored Nov 22, 2024
1 parent 73721f8 commit 74f18ec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions postgresql/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
ARG POSTGRES_VERSION=17

FROM postgres:${POSTGRES_VERSION}
ARG PGRATIONAL_GIT_REPO=https://github.com/begriffs/pg_rational.git
ARG PGRATIONAL_VERSION=v0.0.2
WORKDIR /src
RUN apt-get update && \

## Install pg_rational
DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential git postgresql-server-dev-all pgloader && \
git clone https://github.com/begriffs/pg_rational.git && \
DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential git \
postgresql-server-dev-all pgloader && \
git clone ${PGRATIONAL_GIT_REPO} && \
cd pg_rational && \
git checkout ${PGRATIONAL_VERSION} && \
make && \
Expand Down
9 changes: 7 additions & 2 deletions postgresql/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ psql:

.PHONY: shell
shell:
@make --no-print-directory docker compose-shell SERVICE=psotgres
@make --no-print-directory docker compose-shell SERVICE=postgres

.PHONY: client # Get client certificate and private key files
client:
Expand Down Expand Up @@ -66,7 +66,12 @@ localdb: client

.PHONY: chinook # Import Chinook sample database
chinook:
docker compose --env-file=${ENV_FILE} exec postgres /bin/sh -c 'createdb chinook && psql -c "create role chinook; grant chinook to $${POSTGRES_DB};" && PGUSER=$${POSTGRES_DB} pgloader https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite_AutoIncrementPKs.sqlite pgsql:///chinook'
@POSTGRES_DB=$$(${BIN}/dotenv -f ${ENV_FILE} get POSTGRES_DB); set -x; docker compose --env-file=${ENV_FILE} exec postgres /bin/sh -c 'createdb chinook && PGUSER=root pgloader https://github.com/lerocha/chinook-database/raw/master/ChinookDatabase/DataSources/Chinook_Sqlite_AutoIncrementPKs.sqlite pgsql:///chinook && psql -c "create role chinook;" && psql -d chinook -c "GRANT chinook to $${POSTGRES_DB}; GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO chinook; GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO chinook;"'

.PHONY: drop-chinook # Delete the chinook sample database
drop-chinook:
docker compose --env-file=${ENV_FILE} exec postgres /bin/sh -c 'psql -X -c "drop database chinook"' || true
docker compose --env-file=${ENV_FILE} exec postgres /bin/sh -c 'psql -X -c "drop role chinook"' || true

.PHONY: psql-alias # Get the psql alias with baked connection string
psql-alias:
Expand Down
4 changes: 4 additions & 0 deletions postgresql/init-user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ set -e
## hook to create the POSTGRES_LIMITED_USER on fresh DB initialization.
psql -v ON_ERROR_STOP=1 --username "${POSTGRES_USER}" --dbname "${POSTGRES_DB}" <<-EOF
CREATE USER "${POSTGRES_LIMITED_USER}";
GRANT USAGE ON SCHEMA public TO "${POSTGRES_LIMITED_USER}";
GRANT CREATE ON SCHEMA public TO "${POSTGRES_LIMITED_USER}";
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL PRIVILEGES ON TABLES TO ${POSTGRES_LIMITED_USER};
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL PRIVILEGES ON SEQUENCES TO ${POSTGRES_LIMITED_USER};
CREATE EXTENSION pg_rational;
EOF

0 comments on commit 74f18ec

Please sign in to comment.