pg init script to configure db on start
- create users & dbs - setup db permissions - install extensions
This commit is contained in:
parent
baaaa3e8d6
commit
491350bc58
|
@ -22,13 +22,37 @@
|
|||
};
|
||||
ports = [ "5432:5432" ];
|
||||
volumes = [
|
||||
"/mnt/postgres/data:/var/lib/postgres/data"
|
||||
"${pkgs.writeScript "load_extensions" ''
|
||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<EOF
|
||||
create extension postgis;
|
||||
select * FROM pg_extension;
|
||||
EOF
|
||||
''}:/docker-entrypoint-initdb.d/"
|
||||
"/mnt/postgres:/var/lib/postgresql/data"
|
||||
|
||||
# PG init script
|
||||
"${pkgs.writeScript "init.sh" ''
|
||||
#!/bin/bash
|
||||
|
||||
# Create additional databases
|
||||
psql -v --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
||||
create database bitcoin;
|
||||
create database osm;
|
||||
EOSQL
|
||||
|
||||
# Create additional users
|
||||
psql -v --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
||||
create user gis;
|
||||
create user satoshi;
|
||||
EOSQL
|
||||
|
||||
# Setup bitcoin db
|
||||
psql -v --username "$POSTGRES_USER" --dbname "bitcoin" <<-EOSQL
|
||||
grant all privileges on database bitcoin to satoshi;
|
||||
EOSQL
|
||||
|
||||
# Setup osm db
|
||||
psql -v --username "$POSTGRES_USER" --dbname "osm" <<-EOSQL
|
||||
grant all privileges on database osm to gis;
|
||||
create extension if not exists postgis;
|
||||
create extension if not exists hstore;
|
||||
EOSQL
|
||||
|
||||
''}:/docker-entrypoint-initdb.d/init.sh"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue