Skip to content

Commit 0d2b671

Browse files
committed
opensips-cp: fix reimporting db schema
1 parent d66e2d6 commit 0d2b671

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

etc/opensips-cp/docker-entrypoint.d/00_config_db.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,19 @@ sed -i "s/localhost/${MYSQL_IP}/g" /var/www/html/opensips-cp/config/db.inc.php
99

1010
sed -i "s/127.0.0.1/${OPENSIPS_IP}/g" /var/www/html/opensips-cp/config/db_schema.mysql
1111

12-
add_table /var/www/html/opensips-cp/config/db_schema.mysql
12+
exists=$(
13+
mysql -N -s \
14+
-h "$MYSQL_IP" -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" -D "$MYSQL_DATABASE" \
15+
-e "SELECT EXISTS(
16+
SELECT 1 FROM information_schema.tables
17+
WHERE table_schema='${MYSQL_DATABASE}'
18+
AND table_name='ocp_tools_config'
19+
);" || echo 0
20+
)
21+
22+
if [[ "$exists" == "1" ]]; then
23+
echo "Schema present. Skipping import."
24+
else
25+
echo "Schema missing (at least ocp_tools_config). Importing..."
26+
add_table "/var/www/html/opensips-cp/config/db_schema.mysql"
27+
fi

0 commit comments

Comments
 (0)