Skip to content

platform/#3349: allow minor version in MySQL configuration #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

Monska85
Copy link
Contributor

@Monska85 Monska85 commented Jan 28, 2025

PR Type

Enhancement


Description

  • Added support for MySQL minor versions in database configuration
  • Modified version validation in Terraform to check only major version using startswith
  • Updated shell script to handle minor versions in MySQL version checks
  • Maintains backward compatibility with existing MySQL 5.7 and 8.0 major versions

Changes walkthrough 📝

Relevant files
Enhancement
main.tf
Update MySQL version validation to support minor versions

main.tf

  • Modified database version validation to support minor versions by
    using startswith condition instead of exact match
  • +1/-1     
    execute_sql.sh
    Update MySQL version checks in SQL execution script           

    scripts/execute_sql.sh

  • Updated MySQL version checks to match only major version using string
    substring
  • Modified version comparison for both MySQL 5.7 and 8.0 to support
    minor versions
  • +2/-2     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    @sparkfabrik-ai-bot
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Version Check

    The substring check for MySQL version using ${MYSQL_VERSION:0:9} assumes a specific string format. Validate that this will work correctly with all possible version string formats from the cloud provider.

    if [ "${MYSQL_VERSION:0:9}" = "MYSQL_5_7" ]; then
    mysql --host=${CLOUDSQL_PROXY_HOST} --port=${CLOUDSQL_PROXY_PORT} --user=${CLOUDSQL_PRIVILEGED_USER_NAME} --password=${CLOUDSQL_PRIVILEGED_USER_PASSWORD} --execute="REVOKE ALL PRIVILEGES, GRANT OPTION FROM '${USER}'@'${USER_HOST}'; GRANT ALL ON ${DATABASE}.* TO ${USER}@'${USER_HOST}';"
    fi
    
    if [ "${MYSQL_VERSION:0:9}" = "MYSQL_8_0" ]; then
    mysql --host=${CLOUDSQL_PROXY_HOST} --port=${CLOUDSQL_PROXY_PORT} --user=${CLOUDSQL_PRIVILEGED_USER_NAME} --password=${CLOUDSQL_PRIVILEGED_USER_PASSWORD} --execute="REVOKE cloudsqlsuperuser FROM '${USER}'@'${USER_HOST}'; GRANT ALL ON ${DATABASE}.* TO ${USER}@'${USER_HOST}';"

    @sparkfabrik-ai-bot
    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add error handling for unsupported database versions to prevent silent failures

    Add an else clause to handle unsupported MySQL versions, preventing silent failures
    when an unexpected version is encountered.

    scripts/execute_sql.sh [23-29]

     if [ "${MYSQL_VERSION:0:9}" = "MYSQL_5_7" ]; then
       mysql --host=${CLOUDSQL_PROXY_HOST} --port=${CLOUDSQL_PROXY_PORT} --user=${CLOUDSQL_PRIVILEGED_USER_NAME} --password=${CLOUDSQL_PRIVILEGED_USER_PASSWORD} --execute="REVOKE ALL PRIVILEGES, GRANT OPTION FROM '${USER}'@'${USER_HOST}'; GRANT ALL ON ${DATABASE}.* TO ${USER}@'${USER_HOST}';"
    +elif [ "${MYSQL_VERSION:0:9}" = "MYSQL_8_0" ]; then
    +  mysql --host=${CLOUDSQL_PROXY_HOST} --port=${CLOUDSQL_PROXY_PORT} --user=${CLOUDSQL_PRIVILEGED_USER_NAME} --password=${CLOUDSQL_PRIVILEGED_USER_PASSWORD} --execute="REVOKE cloudsqlsuperuser FROM '${USER}'@'${USER_HOST}'; GRANT ALL ON ${DATABASE}.* TO ${USER}@'${USER_HOST}';"
    +else
    +  echo "Error: Unsupported MySQL version: ${MYSQL_VERSION}"
    +  exit 1
     fi
     
    -if [ "${MYSQL_VERSION:0:9}" = "MYSQL_8_0" ]; then
    -  mysql --host=${CLOUDSQL_PROXY_HOST} --port=${CLOUDSQL_PROXY_PORT} --user=${CLOUDSQL_PRIVILEGED_USER_NAME} --password=${CLOUDSQL_PRIVILEGED_USER_PASSWORD} --execute="REVOKE cloudsqlsuperuser FROM '${USER}'@'${USER_HOST}'; GRANT ALL ON ${DATABASE}.* TO ${USER}@'${USER_HOST}';"
    -fi
    -
    Suggestion importance[1-10]: 9

    Why: The suggestion adds crucial error handling for unsupported MySQL versions, preventing silent failures and improving system reliability. This is particularly important as the code deals with database privileges and security.

    9

    @Monska85 Monska85 force-pushed the feat/allow_minor_mysql_versions branch from dfcddb7 to f904f14 Compare January 28, 2025 11:35
    @Monska85 Monska85 merged commit cd3dcd6 into main Jan 28, 2025
    1 check passed
    @Monska85 Monska85 deleted the feat/allow_minor_mysql_versions branch January 28, 2025 11:38
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant