update @native
Some checks failed
Setup Docker Action / setup_docker (3.12.7) (push) Has been skipped
Setup Native Action / setup_native (3.12.7) (push) Failing after 1m22s

This commit is contained in:
hoangvv 2025-01-15 11:37:04 +07:00
parent 4b6bff7c65
commit 817326dac8

View File

@ -197,21 +197,23 @@ Generate_Config_Native(){
ADDONS=${1:-}
REPO_NAME=$(basename "$(git rev-parse --show-toplevel)" | sed -E 's/[.-]/_/g')
USER="${REPO_NAME:-"default_repo"}"
# Convert to lowercase
USER="${USER,,}"
PASSWORD="$(openssl rand -hex 24)"
# Check if the user already exists
USER_EXISTS=$(psql "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -t -A -c "SELECT COUNT(*) FROM pg_roles WHERE rolname='$USER';")
if [ "$USER_EXISTS" -eq 0 ]; then
# User does not exist, create the user
Show 2 "Create the new PostgreSQL username: $USER with password: $PASSWORD"
psql "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -c "CREATE USER $USER WITH PASSWORD '$PASSWORD';"
Show 2 " Grant $USER superuser (admin) privileges"
psql "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -c "ALTER USER $USER WITH SUPERUSER;"
else
# User exists, update the password
Show 2 "User $USER already exists, updating password to $PASSWORD"
psql "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -c "ALTER USER $USER WITH PASSWORD '$PASSWORD';"
fi
if [ $USER_EXISTS -eq 0 ]; then
# User does not exist, create the user
Show 2 "Create the new PostgreSQL username: $USER with password: $PASSWORD"
psql "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -c "CREATE USER $USER WITH PASSWORD '$PASSWORD';"
Show 2 "Grant $USER superuser (admin) privileges"
psql "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -c "ALTER USER $USER WITH SUPERUSER;"
else
# User exists, update the password (do not try to create)
Show 2 "User $USER already exists, updating password to $PASSWORD"
psql "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -c "ALTER USER $USER WITH PASSWORD '$PASSWORD';"
fi
${PYTHON} "$SETUP_PATH/gen_config.py" --db_user $USER --db_pass $PASSWORD --deploy_path "$(pwd)" \
--addons_path $ADDONS --db_port $DB_PORT --db_server $DB_SERVER
Show 0 " Generate Config Complete"