Skip to content

Commit 6a2d929

Browse files
axeIIonedr0p
andauthored
✨🐘 feat(postgres-init): Add support for UTF-8 database creation (#452)
Co-authored-by: Devin Buhl <[email protected]>
1 parent 67d2dc4 commit 6a2d929

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

apps/postgres-init/entrypoint.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# This is most commonly set to the user 'postgres'
44
export INIT_POSTGRES_SUPER_USER=${INIT_POSTGRES_SUPER_USER:-postgres}
55
export INIT_POSTGRES_PORT=${INIT_POSTGRES_PORT:-5432}
6+
export INIT_POSTGRES_UTF8=${INIT_POSTGRES_UTF8:-"false"}
67

78
if [[ -z "${INIT_POSTGRES_HOST}" ||
89
-z "${INIT_POSTGRES_SUPER_PASS}" ||
@@ -53,8 +54,13 @@ for dbname in ${INIT_POSTGRES_DBNAME}; do
5354
--command "SELECT 1 FROM pg_database WHERE datname = '${dbname}'"
5455
)
5556
if [[ -z "${database_exists}" ]]; then
56-
printf "\e[1;32m%-6s\e[m\n" "Create Database ${dbname} ..."
57-
createdb --owner "${INIT_POSTGRES_USER}" "${dbname}"
57+
if [[ "${INIT_POSTGRES_UTF8}" == "true" ]]; then
58+
printf "\e[1;32m%-6s\e[m\n" "Create Database ${dbname} with UTF8 encoding ..."
59+
createdb --template template0 --encoding UTF8 --owner "${INIT_POSTGRES_USER}" "${dbname}"
60+
else
61+
printf "\e[1;32m%-6s\e[m\n" "Create Database ${dbname} ..."
62+
createdb --owner "${INIT_POSTGRES_USER}" "${dbname}"
63+
fi
5864
database_init_file="/initdb/${dbname}.sql"
5965
if [[ -f "${database_init_file}" ]]; then
6066
printf "\e[1;32m%-6s\e[m\n" "Initialize Database ..."

0 commit comments

Comments
 (0)