Skip to content

Commit 690c39b

Browse files
authored
MG4: Fix permissions issue in create_db_and_user.sh (#229)
1 parent dfb9471 commit 690c39b

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

distro/data/postgresql/openelis/create_db_and_user.sh

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,35 +46,27 @@ if [[ ! -f "${SITEINFO_SQL}" ]]; then
4646
exit 1
4747
fi
4848

49-
if [[ -f "${OPENELIS_SQL}" ]]; then
49+
# Function to filter out plain `CREATE SCHEMA clinlims;` (not commented and without IF NOT EXISTS)
50+
filter_openelis_sql() {
5051
awk '{
5152
orig=$0
5253
lo=tolower($0)
5354
if (lo ~ /^[[:space:]]*create[[:space:]]+schema[[:space:]]+clinlims[[:space:]]*;[[:space:]]*$/ && lo !~ /if[[:space:]]+not[[:space:]]+exists/) {
5455
if (orig !~ /^[[:space:]]*--/) {
56+
# Comment out the line instead of executing it
5557
print "-- " orig
5658
next
5759
}
5860
}
5961
print
60-
}' "${OPENELIS_SQL}" > "${OPENELIS_SQL}.tmp"
61-
62-
if ! cmp -s "${OPENELIS_SQL}" "${OPENELIS_SQL}.tmp"; then
63-
echo "Backing up ${OPENELIS_SQL} to ${OPENELIS_SQL}.bak"
64-
cp "${OPENELIS_SQL}" "${OPENELIS_SQL}.bak"
65-
mv "${OPENELIS_SQL}.tmp" "${OPENELIS_SQL}"
66-
echo "Commented out plain CREATE SCHEMA clinlims; in ${OPENELIS_SQL}"
67-
else
68-
rm "${OPENELIS_SQL}.tmp"
69-
echo "No plain 'CREATE SCHEMA clinlims;' found or already commented/has IF NOT EXISTS; no change."
70-
fi
71-
fi
62+
}' "${OPENELIS_SQL}"
63+
}
7264

7365
# Load schema/data into the newly created database
74-
echo "Loading ${OPENELIS_SQL} into ${db_name}..."
75-
psql -v ON_ERROR_STOP=1 --username admin --dbname "$db_name" -f "${OPENELIS_SQL}"
66+
echo "Loading ${OPENELIS_SQL} into ${db_name} (filtered in-memory, no temp file)..."
67+
filter_openelis_sql | psql -v ON_ERROR_STOP=1 --username admin --dbname "$db_name"
7668

7769
echo "Loading ${SITEINFO_SQL} into ${db_name}..."
7870
psql -v ON_ERROR_STOP=1 --username admin --dbname "$db_name" -f "${SITEINFO_SQL}"
7971

80-
echo "SQL files imported successfully."
72+
echo "SQL files imported successfully."

0 commit comments

Comments
 (0)