Skip to content

Commit

Permalink
fix(initdb): fix if conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Hazmi35 committed Oct 9, 2024
1 parent 49cfb33 commit 3526ceb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
13 changes: 8 additions & 5 deletions initdb/000_alter_owner_temp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ if [ $POSTGRES_USER != "postgres" ]; then
exit 1
fi

# Find "timescaledb.telemetry_level" in the postgresql.conf file
if grep -q "timescaledb.telemetry_level" ${POSTGRESQL_CONF_DIR}/postgresql.conf; then
# Find "timescaledb.telemetry_level" in the postgresql.conf file, if not found, then alter the owner of the databases
if ! grep -q "timescaledb.telemetry_level" ${POSTGRESQL_CONF_DIR}/postgresql.conf; then
# Change the owner of the initial databases to the POSTGRES_USER
psql -U postgres postgres -f "ALTER DATABASE postgres OWNER TO $POSTGRES_USER;"
psql -U postgres template1 -f "ALTER DATABASE template1 OWNER TO $POSTGRES_USER;"
psql -U postgres postgres -f "ALTER DATABASE postgres OWNER TO $POSTGRES_USER"
psql -U postgres template1 -f "ALTER DATABASE template1 OWNER TO $POSTGRES_USER"

# Change the owner of the POSTGRES_DB to the POSTGRES_USER
psql -U postgres $POSTGRES_DB -f "ALTER DATABASE $POSTGRES_DB OWNER TO $POSTGRES_USER;"
psql -U postgres $POSTGRES_DB -f "ALTER DATABASE $POSTGRES_DB OWNER TO $POSTGRES_USER"
fi

# Mark to revert the changes
touch /tmp/alter_owner_temp_revert
fi
11 changes: 6 additions & 5 deletions initdb/999_alter_owner_temp_revert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ if [ $POSTGRES_USER != "postgres" ]; then
exit 1
fi

# Find "timescaledb.telemetry_level" in the postgresql.conf file
if grep -q "timescaledb.telemetry_level" ${POSTGRESQL_CONF_DIR}/postgresql.conf; then
# If there is /tmp/alter_owner_temp_revert, revert the changes
if [ -f /tmp/alter_owner_temp_revert ]; then
# Change the owner of the initial databases to the POSTGRES_USER
psql -U postgres postgres -f "ALTER DATABASE postgres OWNER TO postgres;"
psql -U postgres template1 -f "ALTER DATABASE template1 OWNER TO postgres;"
psql -U postgres postgres -f "ALTER DATABASE postgres OWNER TO postgres"
psql -U postgres template1 -f "ALTER DATABASE template1 OWNER TO postgres"

# Change the owner of the POSTGRES_DB to the POSTGRES_USER
psql -U postgres $POSTGRES_DB -f "ALTER DATABASE $POSTGRES_DB OWNER TO postgres;"
psql -U postgres $POSTGRES_DB -f "ALTER DATABASE $POSTGRES_DB OWNER TO postgres"
rm /tmp/alter_owner_temp_revert
fi
fi

0 comments on commit 3526ceb

Please sign in to comment.