Skip to content

Commit

Permalink
try to log in on mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
timdiggins committed Nov 9, 2024
1 parent 60b17a1 commit 7f810e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
env:
BUNDLE_GEMFILE: "rails_${{ matrix.rails }}.gemfile"
DB_HOST: 127.0.0.1
MYSQL_ROOT_PASSWORD: active_record_union
steps:
- uses: actions/checkout@v4

Expand Down
10 changes: 6 additions & 4 deletions bin/create-db-users
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@ GREEN='\033[0;32m'
RESET_COLOR='\033[0m'

if [ -n "$1" ]; then cat <<'HELP'; exit; fi
Usage: script/create-db-users
Usage: bin/create-db-users
Create the active_record_union database users for all the supported databases.
If the `DB` environment variable is set, do the above only for that database.
HELP

USER='active_record_union'
PASS='active_record_union'
DB_HOST=${DB_HOST:-localhost}

set -e
log() { if [ -t 1 ]; then echo -e >&2 "${GREEN}create-db-users: $@${RESET_COLOR}"; else echo >&2 "$@"; fi }

create_mysql_user() {
if [ -n "$MYSQL_ROOT_PASSWORD" ]; then PASS_ARG="--password=$MYSQL_ROOT_PASSWORD"; else PASS_ARG="-p"; fi
if mysql -s -u"$USER" -p"$PASS" -e '' 2>/dev/null; then return; fi
log "Creating MySQL '$USER' user. MySQL root password required."
mysql --verbose -uroot -p <<SQL
CREATE USER '$USER'@'localhost' IDENTIFIED BY '$PASS';
GRANT ALL PRIVILEGES ON \`test_active_record_union\`.* TO '$USER'@'localhost';
mysql --verbose -uroot $PASS_ARG <<SQL
CREATE USER '$USER'@'$DB_HOST' IDENTIFIED BY '$PASS';
GRANT ALL PRIVILEGES ON \`test_active_record_union\`.* TO '$USER'@'$DB_HOST';
SQL
}

Expand Down

0 comments on commit 7f810e7

Please sign in to comment.