Skip to content

Commit

Permalink
Avoid downloading database again if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
campos20 committed Sep 30, 2024
1 parent c146f50 commit 85a9a3c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ services:
entrypoint: >
sh -c "
apt update && apt install curl unzip mysql-client wget -y &&
result=$(mysql -h mysql -sN -u root -e 'use wca_development; select datediff(now(), max(results_posted_at)) from Competitions;' || echo 999) &&
echo 'Days since last update: ' $result &&
if [ -n \"$result\" ] && [ $result -lt 7 ]; then
echo 'Database is already up to date, skipping restoration.'
exit 0
else
echo 'Database is outdated, restoring...'
fi &&
echo 'Downloading WCA database dump, this may take a while...' &&
wget -q https://www.worldcubeassociation.org/wst/wca-developer-database-dump.zip &&
rm -rf wca-developer-database-dump.sql &&
unzip wca-developer-database-dump.zip &&
echo 'Restoring WCA database. This also may take a while...' &&
mysql -h mysql -u root -e 'drop database if exists wca_development; create database wca_development; use wca_development; source wca-developer-database-dump.sql;' &&
echo 'Restoration complete!'"
echo 'Restoration complete!'
"
volumes:
- mysql-data:/var/lib/mysql
Expand Down

0 comments on commit 85a9a3c

Please sign in to comment.