Skip to content

Added POSTGRES_DB variable to optionally specify DB name #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions 8.4/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ if [ "$1" = 'postgres' ]; then
fi

: ${POSTGRES_USER:=postgres}
if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER'
else
op='CREATE'
: ${POSTGRES_DB:=$POSTGRES_USER}

if [ "$POSTGRES_DB" != 'postgres' ]; then
gosu postgres postgres --single -jE <<-EOSQL
CREATE DATABASE "$POSTGRES_USER" ;
CREATE DATABASE "$POSTGRES_DB" ;
EOSQL
echo
fi

if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER'
else
op='CREATE'
fi

gosu postgres postgres --single -jE <<-EOSQL
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
EOSQL
Expand Down
15 changes: 10 additions & 5 deletions 9.0/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ if [ "$1" = 'postgres' ]; then
fi

: ${POSTGRES_USER:=postgres}
if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER'
else
op='CREATE'
: ${POSTGRES_DB:=$POSTGRES_USER}

if [ "$POSTGRES_DB" != 'postgres' ]; then
gosu postgres postgres --single -jE <<-EOSQL
CREATE DATABASE "$POSTGRES_USER" ;
CREATE DATABASE "$POSTGRES_DB" ;
EOSQL
echo
fi

if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER'
else
op='CREATE'
fi

gosu postgres postgres --single -jE <<-EOSQL
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
EOSQL
Expand Down
15 changes: 10 additions & 5 deletions 9.1/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ if [ "$1" = 'postgres' ]; then
fi

: ${POSTGRES_USER:=postgres}
if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER'
else
op='CREATE'
: ${POSTGRES_DB:=$POSTGRES_USER}

if [ "$POSTGRES_DB" != 'postgres' ]; then
gosu postgres postgres --single -jE <<-EOSQL
CREATE DATABASE "$POSTGRES_USER" ;
CREATE DATABASE "$POSTGRES_DB" ;
EOSQL
echo
fi

if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER'
else
op='CREATE'
fi

gosu postgres postgres --single -jE <<-EOSQL
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
EOSQL
Expand Down
15 changes: 10 additions & 5 deletions 9.2/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ if [ "$1" = 'postgres' ]; then
fi

: ${POSTGRES_USER:=postgres}
if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER'
else
op='CREATE'
: ${POSTGRES_DB:=$POSTGRES_USER}

if [ "$POSTGRES_DB" != 'postgres' ]; then
gosu postgres postgres --single -jE <<-EOSQL
CREATE DATABASE "$POSTGRES_USER" ;
CREATE DATABASE "$POSTGRES_DB" ;
EOSQL
echo
fi

if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER'
else
op='CREATE'
fi

gosu postgres postgres --single -jE <<-EOSQL
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
EOSQL
Expand Down
15 changes: 10 additions & 5 deletions 9.3/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ if [ "$1" = 'postgres' ]; then
fi

: ${POSTGRES_USER:=postgres}
if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER'
else
op='CREATE'
: ${POSTGRES_DB:=$POSTGRES_USER}

if [ "$POSTGRES_DB" != 'postgres' ]; then
gosu postgres postgres --single -jE <<-EOSQL
CREATE DATABASE "$POSTGRES_USER" ;
CREATE DATABASE "$POSTGRES_DB" ;
EOSQL
echo
fi

if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER'
else
op='CREATE'
fi

gosu postgres postgres --single -jE <<-EOSQL
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
EOSQL
Expand Down
15 changes: 10 additions & 5 deletions 9.4/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ if [ "$1" = 'postgres' ]; then
fi

: ${POSTGRES_USER:=postgres}
if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER'
else
op='CREATE'
: ${POSTGRES_DB:=$POSTGRES_USER}

if [ "$POSTGRES_DB" != 'postgres' ]; then
gosu postgres postgres --single -jE <<-EOSQL
CREATE DATABASE "$POSTGRES_USER" ;
CREATE DATABASE "$POSTGRES_DB" ;
EOSQL
echo
fi

if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER'
else
op='CREATE'
fi

gosu postgres postgres --single -jE <<-EOSQL
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
EOSQL
Expand Down
15 changes: 10 additions & 5 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@ if [ "$1" = 'postgres' ]; then
fi

: ${POSTGRES_USER:=postgres}
if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER'
else
op='CREATE'
: ${POSTGRES_DB:=$POSTGRES_USER}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also just now realizing this is a break from the current behavior, where specifying POSTGRES_USER still gives me a default POSTGRES_DB of postgres -- I'm not sure which way to feel. I think I prefer this behavior, personally, especially since it's more consistent with what I think the user expectations would be.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I mean, I prefer what you've got here, not how it works today.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yosifkit @md5 thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we get the default postgres db from the gosu postgres initdb line above? I think @rothgar alluded to that in one of the comments (the fact that the default postgres db would still exist).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to change any code for dropping the default postgres table but if that would be prefered I could.
I assume I could just add DROP DATABASE IF EXISTS postgres to the if statement that creates the POSTGRES_DB

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that makes a lot of sense unless you're also going to drop the postgres user. Seems like more trouble that it's worth and also like the sort of thing that could break implicit assumptions. It definitely doesn't need to be muddled into this PR.


if [ "$POSTGRES_DB" != 'postgres' ]; then
gosu postgres postgres --single -jE <<-EOSQL
CREATE DATABASE "$POSTGRES_USER" ;
CREATE DATABASE "$POSTGRES_DB" ;
EOSQL
echo
fi

if [ "$POSTGRES_USER" = 'postgres' ]; then
op='ALTER'
else
op='CREATE'
fi

gosu postgres postgres --single -jE <<-EOSQL
$op USER "$POSTGRES_USER" WITH SUPERUSER $pass ;
EOSQL
Expand Down