Skip to content

Fix(fix/Default_pro): fix install first pro script - #326

Closed
linushuan wants to merge 2 commits into
TFcis:v2.0from
linushuan:fix/Default_pro
Closed

linushuan wants to merge 2 commits into
TFcis:v2.0from
linushuan:fix/Default_pro

Conversation

@linushuan

Copy link
Copy Markdown
Collaborator

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

Because the script will run install HelloTOJ each launch time,
I fix it that now might just have install HelloTOJ once.
Copilot AI lite review requested due to automatic review settings September 26, 2026 13:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 High severity

Open (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.

Comment thread scripts/runserver.sh Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@tobiichi3227

Copy link
Copy Markdown
Collaborator

@uyo9 Does this PR fix the issue?

@uyo9

uyo9 commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

@uyo9 Does this PR fix the issue?

I've done several reviews. Waiting for approval. Thanks.

Comment thread scripts/runserver.sh
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PROBLEM_COUNT

Comment thread scripts/runserver.sh
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
fi

Otherwise, it causes the following error:

cp: cannot stat 'config.py': No such file or directory

Comment thread scripts/runserver.sh

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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.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

rm scripts/.docker-init.env

@uyo9

uyo9 commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Here I provide another solution for this problem. Any recommendations are welcome.
See #327.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants