Repository navigation
Conversation
Because the script will run install HelloTOJ each launch time, I fix it that now might just have install HelloTOJ once.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The database query must use the configured password and distinguish authentication failures from an empty database.
Review effort: Lite
Findings: 1
What changed in this PR
Updates startup logic to install the default HelloTOJ problem only when the database is empty.
Changes:
- Counts existing problems before initialization.
- Prevents repeated first-problem installation attempts.
| File | Summary |
|---|---|
scripts/runserver.sh |
Adds database-based first-install detection; currently hard-codes the database password and masks authentication failures. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@uyo9 Does this PR fix the issue? |
I've done several reviews. Waiting for approval. Thanks. |
| should_install_first_problem=false | ||
| if [[ -f docker-dev || -f docker-release ]] && [ -d static-tmp ]; then | ||
| PROBLEM_COUNT=$(PGPASSWORD="$(sed -n 's/^DB_PASSWORD=//p' scripts/.docker-init.env)" psql -h "${DB_CONTAINER_NAME}" -U ntoj -d ntoj -tAc "SELECT count(*) FROM problem" 2>/dev/null || echo "0") | ||
| PROB_COUNT=$(echo "$PROB_COUNT" | xargs) |
| PROB_COUNT=$(echo "$PROB_COUNT" | xargs) | ||
|
|
||
| if [[ -f docker-dev || -f docker-release ]] && [ -d static-tmp ] && [ "$PROBLEM_COUNT" -eq 0 ]; then | ||
| should_install_first_problem=true |
There was a problem hiding this comment.
PROBLEM_COUNT check should be separated from docker-init:
if [[ -f docker-dev || -f docker-release ]] && [ -d static-tmp ]; then
if [ "$PROBLEM_COUNT" -eq 0 ]; then
should_install_first_problem=true
fi
./scripts/docker-init.sh
fiOtherwise, it causes the following error:
cp: cannot stat 'config.py': No such file or directory
|
|
||
| should_install_first_problem=false | ||
| if [[ -f docker-dev || -f docker-release ]] && [ -d static-tmp ]; then | ||
| PROBLEM_COUNT=$(PGPASSWORD="$(sed -n 's/^DB_PASSWORD=//p' scripts/.docker-init.env)" psql -h "${DB_CONTAINER_NAME}" -U ntoj -d ntoj -tAc "SELECT count(*) FROM problem" 2>/dev/null || echo "0") |
There was a problem hiding this comment.
.docker-init.env is deleted by docker-init, thereby causing the not found error once I don't restart the container:
sed: can't read scripts/.docker-init.env: No such file or directory
Line 50 in fa96592
|
Here I provide another solution for this problem. Any recommendations are welcome. |

Because the script will run install HelloTOJ each launch time, I fix it that now might just have install HelloTOJ once.