Skip to content

Commit 36c3dfe

Browse files
authored
Merge pull request #70 from cloudfoundry/pr-issue-69-fix-upgrades
Fix broken major upgrade logic
2 parents 4493258 + 2bb0bd6 commit 36c3dfe

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

jobs/postgres/templates/pg_hba.conf.erb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
local all vcap peer
2-
host all vcap 127.0.0.1/32 md5
3-
host all vcap ::1/128 md5
1+
local all vcap trust
2+
host all vcap 127.0.0.1/32 trust
3+
host all vcap ::1/128 trust
44
<% if !p("databases.trust_local_connections").nil? && !p("databases.trust_local_connections") %>
55
local all all md5
66
<% else %>
7-
local all all peer
8-
host all all 127.0.0.1/32 md5
9-
host all all ::1/128 md5
7+
local all all trust
8+
host all all 127.0.0.1/32 trust
9+
host all all ::1/128 trust
1010
<% end %>
1111
<% p("databases.roles", []).each do |role| %>
1212
<%=
1313
line=nil
1414
unless role["password"]
15-
line = "hostssl all #{role["name"]} 0.0.0.0/0 cert clientcert=1 "
15+
line = "hostssl all #{role["name"]} 0.0.0.0/0 cert clientcert=verify-full "
1616
line << 'map=cnmap' if role["common_name"]
1717
end
1818
line

jobs/postgres/templates/pgconfig.sh.erb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ pgversion_upgrade_from=postgres-unknown
2626
if [ -f "${VERSION_FILE}" ]; then
2727
pgversion_upgrade_from=$(cat ${VERSION_FILE})
2828
DATA_DIR_OLD="${PG_STORE_DIR}/${pgversion_upgrade_from}"
29-
PACKAGE_DIR_OLD=/var/vcap/packages/${pgversion_upgrade_from}
29+
PACKAGE_DIR_OLD=(/var/vcap/packages/${pgversion_upgrade_from%.*}*)
30+
if [ ! -d "${PACKAGE_DIR_OLD}" ]; then
31+
echo "Unable to find older postgres package to use for major upgrade. Upgrade to and older version first."
32+
exit 1
33+
fi
3034
fi
3135
<%
3236
if !['rfc3339', 'deprecated'].include?(p('databases.logging.format.timestamp'))

jobs/postgres/templates/pre-start.sh.erb

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,12 @@ function main() {
4242
chmod 700 "${PG_STORE_DIR}"
4343

4444
if [ ! -f ${VERSION_FILE} ]; then
45-
for version in "postgres-9.6.8" "postgres-9.6.6" "postgres-9.6.4"; do
46-
if [[ -d "${PG_STORE_DIR}/${version}" ]]; then
47-
if [[ -f "${PG_STORE_DIR}/${version}/postgresql.conf" ]]; then
48-
echo "Creating the PostgreSQL data version file at version ${version}"
49-
echo ${version} > ${VERSION_FILE}
50-
chown -R vcap:vcap "${VERSION_FILE}"
51-
chmod 700 "${VERSION_FILE}"
52-
pgversion_upgrade_from=${version}
53-
DATA_DIR_OLD="${PG_STORE_DIR}/${version}"
54-
PACKAGE_DIR_OLD=/var/vcap/packages/${version}
55-
break
56-
fi
57-
fi
58-
done
45+
existing_data_dirs=$(compgen -G "${PG_STORE_DIR}/postgres-*" || echo "")
46+
47+
if [ -n "${existing_data_dirs}" ]; then
48+
echo "Found existing data dirs that we cannot upgrade from in this release. Upgrade to and older version first."
49+
exit 1
50+
fi
5951
fi
6052

6153
mkdir -p "${LOG_DIR}"

jobs/postgres/templates/utils.sh.erb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ function create_databases() {
5252
echo "Enabling pg_stat_statements extension..."
5353
pgexec "<%= database["name"] %>" "CREATE EXTENSION IF NOT EXISTS pg_stat_statements"
5454
<% end %>
55+
<% p("databases.roles", []).each do |role| %>
56+
echo "Granting public schema access to <%= role["name"] %> on <%= database["name"] %>"
57+
"${PACKAGE_DIR}/bin/psql" \
58+
-U "vcap" \
59+
-p "${PORT}" \
60+
-d "<%= database["name"] %>" \
61+
-c "GRANT ALL ON schema public TO \"<%= role["name"] %>\""
62+
<% end %>
5563

5664
<% end %>
5765
}

0 commit comments

Comments
 (0)