Skip to content

Commit 0205800

Browse files
authored
Fix(clone): allow port in DB_BASE_URL url (#35511)
This fixes issue #35505 and properly splits if there is a port specified in the url
1 parent c016227 commit 0205800

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

dotCMS/src/main/docker/original/ROOT/srv/10-import-env.sh

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
## Drops the contents of the dotCMS database in preperation for a new import (only if requested)
55
drop_db_tables () {
66
echo "- DOT_IMPORT_DROP_DB - attempting to drop db schema"
7-
psql -h "${DB_HOST}" -d "${DB_NAME}" -U "${DB_USERNAME}" -c "DROP SCHEMA public CASCADE;CREATE SCHEMA public;GRANT ALL ON SCHEMA public TO public;"
7+
psql -h "${DB_HOST}" -p "${DB_PORT}" -d "${DB_NAME}" -U "${DB_USERNAME}" -c "DROP SCHEMA public CASCADE;CREATE SCHEMA public;GRANT ALL ON SCHEMA public TO public;"
88
}
99

1010
## This checks active connections to the dotCMS database - we can only proceed if there are no connections
1111
check_active_connections() {
1212

13-
ACTIVE=$(psql -h "$DB_HOST" -d "$DB_NAME" -U "$DB_USERNAME" -qtAX -c \
13+
ACTIVE=$(psql -h "$DB_HOST" -p "$DB_PORT" -d "$DB_NAME" -U "$DB_USERNAME" -qtAX -c \
1414
"SELECT count(*) FROM pg_stat_activity
1515
WHERE datname = '$DB_NAME'
1616
AND pid != pg_backend_pid()
@@ -30,7 +30,7 @@ import_postgres () {
3030

3131
if [ -s $DB_BACKUP_FILE ]; then
3232
# Check if database already has data (inode table exists with records)
33-
INODE_COUNT=$(psql -h "${DB_HOST}" -d "${DB_NAME}" -U "${DB_USERNAME}" -qtAX -c \
33+
INODE_COUNT=$(psql -h "${DB_HOST}" -p "${DB_PORT}" -d "${DB_NAME}" -U "${DB_USERNAME}" -qtAX -c \
3434
"SELECT CASE WHEN EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'inode')
3535
THEN (SELECT count(*) FROM inode) ELSE 0 END" 2>/dev/null | tr -d '[:space:]')
3636

@@ -40,7 +40,7 @@ import_postgres () {
4040
fi
4141

4242
# Run the query using psql
43-
cat $DB_BACKUP_FILE | gzip -d | psql -h "${DB_HOST}" -d "${DB_NAME}" -U "${DB_USERNAME}"
43+
cat $DB_BACKUP_FILE | gzip -d | psql -h "${DB_HOST}" -p "${DB_PORT}" -d "${DB_NAME}" -U "${DB_USERNAME}"
4444

4545
fi
4646

@@ -144,10 +144,17 @@ export IMPORT_COMPLETE=$IMPORT_DATA_DIR/import_complete.txt
144144
export DOT_IMPORT_ALL_ASSETS=${DOT_IMPORT_ALL_ASSETS:-"false"}
145145

146146

147-
# Extract hostname and database name from JDBC URL (jdbc:postgresql://host/dbname)
148-
export DB_HOST="${DB_BASE_URL#jdbc:postgresql://}" # Remove prefix -> host/dbname
149-
export DB_HOST="${DB_HOST%%/*}" # Remove /dbname -> host
150-
export DB_NAME="${DB_BASE_URL##*/}" # Remove everything before last / -> dbname
147+
# Extract hostname, port, and database name from JDBC URL
148+
# (jdbc:postgresql://host[:port]/dbname)
149+
DB_URL_REST="${DB_BASE_URL#jdbc:postgresql://}" # host[:port]/dbname
150+
DB_HOSTPORT="${DB_URL_REST%%/*}" # host[:port]
151+
export DB_HOST="${DB_HOSTPORT%%:*}" # host
152+
if [ "$DB_HOSTPORT" = "$DB_HOST" ]; then
153+
export DB_PORT="5432"
154+
else
155+
export DB_PORT="${DB_HOSTPORT##*:}"
156+
fi
157+
export DB_NAME="${DB_BASE_URL##*/}" # dbname
151158
export PGPASSWORD="${DB_PASSWORD}"
152159

153160
# Clear the password from environment on exit

0 commit comments

Comments
 (0)