Skip to content

Commit ec5ef8b

Browse files
author
Sameer Naik
committed
This option deprecates the DB_UNACCENT parameter
1 parent 33fa487 commit ec5ef8b

5 files changed

Lines changed: 34 additions & 4 deletions

File tree

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
**latest**
4+
- added `DB_EXTENSION` configuration parameter
5+
36
**9.4-12**
47
- removed use of single-user mode
58
- added `DB_TEMPLATE` variable to specify the database template

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- [Creating databases](#creating-databases)
1616
- [Enabling unaccent extension](#enabling-unaccent-extension)
1717
- [Granting user access to a database](#granting-user-access-to-a-database)
18+
- [Enabling extensions](#enabling-extensions)
1819
- [Creating replication user](#creating-replication-user)
1920
- [Setting up a replication cluster](#setting-up-a-replication-cluster)
2021
- [Creating a snapshot](#creating-a-snapshot)
@@ -198,6 +199,18 @@ docker run --name postgresql -itd --restart always \
198199

199200
In the above example `dbuser` with be granted access to both the `dbname1` and `dbname2` databases.
200201

202+
# Enabling extensions
203+
204+
The image also packages the [postgres contrib module](http://www.postgresql.org/docs/9.4/static/contrib.html). A comma separated list of modules can be specified using the `DB_EXTENSION` parameter.
205+
206+
```bash
207+
docker run --name postgresql -itd \
208+
--env 'DB_NAME=db1,db2' --env 'DB_EXTENSION=unaccent,pg_trgm' \
209+
sameersbn/postgresql:9.4-16
210+
```
211+
212+
The above command enables the `unaccent` and `pg_trgm` modules on the databases listed in `DB_NAME`, namely `db1` and `db2`.
213+
201214
## Creating replication user
202215

203216
Similar to the creation of a database user, a new PostgreSQL replication user can be created by specifying the `REPLICATION_USER` and `REPLICATION_PASS` variables while starting the container.

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ PostgreSQL:
1212
- DB_TEMPLATE=
1313

1414
- DB_UNACCENT=
15+
- DB_EXTENSION=
1516

1617
- REPLICATION_MODE=
1718
- REPLICATION_USER=

runtime/env-defaults

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ DB_USER=${DB_USER:-}
1818
DB_PASS=${DB_PASS:-}
1919
DB_TEMPLATE=${DB_TEMPLATE:-template1}
2020

21+
DB_EXTENSION=${DB_EXTENSION:-}
22+
2123
DB_UNACCENT=${DB_UNACCENT:-false}

runtime/functions

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,20 @@ create_user() {
305305
fi
306306
}
307307

308+
load_extensions() {
309+
local database=${1?missing argument}
310+
311+
if [[ ${DB_UNACCENT} == true ]]; then
312+
echo "‣ Loading unaccent extension..."
313+
psql -U ${PG_USER} -d ${database} -c "CREATE EXTENSION IF NOT EXISTS unaccent;" >/dev/null 2>&1
314+
fi
315+
316+
for extension in $(awk -F',' '{for (i = 1 ; i <= NF ; i++) print $i}' <<< "${DB_EXTENSION}"); do
317+
echo "‣ Loading ${extension} extension..."
318+
psql -U ${PG_USER} -d ${database} -c "CREATE EXTENSION IF NOT EXISTS ${extension};" >/dev/null 2>&1
319+
done
320+
}
321+
308322
create_database() {
309323
if [[ -n ${DB_NAME} ]]; then
310324
case $REPLICATION_MODE in
@@ -318,10 +332,7 @@ create_database() {
318332
psql -U ${PG_USER} -c "CREATE DATABASE \"${database}\" WITH TEMPLATE = \"${DB_TEMPLATE}\";" >/dev/null
319333
fi
320334

321-
if [[ ${DB_UNACCENT} == true ]]; then
322-
echo "‣ Loading unaccent extension..."
323-
psql -U ${PG_USER} -d ${database} -c "CREATE EXTENSION IF NOT EXISTS unaccent;" >/dev/null 2>&1
324-
fi
335+
load_extensions ${database}
325336

326337
if [[ -n ${DB_USER} ]]; then
327338
echo "‣ Granting access to ${DB_USER} user..."

0 commit comments

Comments
 (0)