Skip to content

Commit 952be3b

Browse files
committed
upgrade pg version, use en flightsdb
1 parent 39dea3d commit 952be3b

8 files changed

Lines changed: 94 additions & 6 deletions

File tree

Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
FROM postgres:12-alpine
1+
FROM postgres:17-alpine
22

33
WORKDIR /scripts
44

5+
COPY config/ /etc/postgresql/
6+
COPY scripts/configure_postgres.sh /docker-entrypoint-initdb.d/00_configure_postgres.sh
7+
RUN chown postgres:postgres /etc/postgresql/*.conf \
8+
&& chmod 600 /etc/postgresql/*.conf \
9+
&& chmod +x /docker-entrypoint-initdb.d/00_configure_postgres.sh
10+
511
COPY scripts/setup_user.sql /scripts
612

713
COPY scripts/salesdb /scripts/salesdb

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
COMPOSE ?= docker compose
2+
13
start:
24
make stop rm || true
35
docker run -it \
@@ -17,3 +19,24 @@ rm:
1719

1820
bash:
1921
docker run --rm -it data-salesdb bash
22+
23+
compose-build:
24+
$(COMPOSE) build
25+
26+
compose:
27+
$(COMPOSE) up --abort-on-container-exit
28+
29+
compose-down:
30+
$(COMPOSE) down -v --remove-orphans
31+
32+
compose-logs:
33+
$(COMPOSE) logs -f
34+
35+
compose-ps:
36+
$(COMPOSE) ps
37+
38+
compose-bash:
39+
$(COMPOSE) run --rm postgres bash
40+
41+
compose-attach:
42+
$(COMPOSE) exec postgres bash

config/pg_hba.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# TYPE DATABASE USER ADDRESS METHOD
2+
3+
local all postgres peer
4+
local all all scram-sha-256
5+
host all postgres 0.0.0.0/0 scram-sha-256
6+
host all postgres ::/0 scram-sha-256
7+
host all student 0.0.0.0/0 scram-sha-256
8+
host all student ::/0 scram-sha-256
9+
host all all 127.0.0.1/32 scram-sha-256
10+
host all all ::1/128 scram-sha-256

config/postgresql.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
listen_addresses = '*'
2+
password_encryption = 'scram-sha-256'

docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
services:
2+
postgres:
3+
build:
4+
context: .
5+
environment:
6+
POSTGRES_PASSWORD: secret
7+
ports:
8+
- "5432:5432"
9+
volumes:
10+
- pgdata:/var/lib/postgresql/data
11+
healthcheck:
12+
test: ["CMD-SHELL", "pg_isready -U postgres -h 127.0.0.1"]
13+
interval: 10s
14+
timeout: 5s
15+
retries: 5
16+
start_period: 5s
17+
18+
volumes:
19+
pgdata:

scripts/configure_postgres.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
set -e
3+
4+
: "${PGDATA:?PGDATA is not set}"
5+
6+
cp /etc/postgresql/postgresql.conf "$PGDATA/postgresql.conf"
7+
cp /etc/postgresql/pg_hba.conf "$PGDATA/pg_hba.conf"
8+
chmod 600 "$PGDATA/postgresql.conf" "$PGDATA/pg_hba.conf"

scripts/flightsdb/flightsdb.tar.xz

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:e8a5ceed973724a7ee842b467f6cc3b107110f98c0e472687f1fd3f9c4469797
3-
size 12201348
2+
oid sha256:ac803445153c4f6f325a40bb36647d83c8c8f398701d66aab5b1ab9bfa74e70d
3+
size 14768668

scripts/setup_user.sql

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
1-
REVOKE ALL ON schema public FROM public;
2-
CREATE ROLE student WITH LOGIN PASSWORD 'student'
3-
NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION VALID UNTIL 'infinity';
1+
DO
2+
$$
3+
BEGIN
4+
IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'student') THEN
5+
CREATE ROLE student
6+
WITH LOGIN PASSWORD 'student'
7+
NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
8+
END IF;
9+
END;
10+
$$;
11+
12+
REVOKE ALL ON SCHEMA public FROM public;
13+
414
GRANT USAGE ON SCHEMA public TO student;
515
GRANT SELECT ON ALL TABLES IN SCHEMA public TO student;
616
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO student;
17+
18+
DO
19+
$$
20+
DECLARE
21+
dbname text := current_database();
22+
BEGIN
23+
EXECUTE format('GRANT CONNECT ON DATABASE %I TO student', dbname);
24+
EXECUTE format('GRANT TEMP ON DATABASE %I TO student', dbname);
25+
END;
26+
$$;

0 commit comments

Comments
 (0)