-
Notifications
You must be signed in to change notification settings - Fork 495
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
Make auto db creation optional with DB_CREATE #558
base: master
Are you sure you want to change the base?
Conversation
Added a `DB_CREATE` option (default `true`) to allow skipping the call to `bundle exec rake db:create`. Particularly important for connecting to databases where the user doesn't have permission to create databases.
A way to address #557. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry it took so long to look at this
DB_CREATE=false | ||
----------------------- | ||
EOM | ||
return $res |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an exit if we are to keep the previous behavior. As is, this will skip db migration and then redmine will continue to try to start, likely leading to more confusing errors.
@@ -1048,8 +1048,27 @@ migrate_database() { | |||
CACHE_VERSION= | |||
[[ -f ${REDMINE_DATA_DIR}/tmp/VERSION ]] && CACHE_VERSION=$(cat ${REDMINE_DATA_DIR}/tmp/VERSION) | |||
if [[ ${REDMINE_VERSION} != ${CACHE_VERSION} ]]; then | |||
if [[ "${DB_CREATE:-true}" == "true" ]] ; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaults should all be set in assets/runtime/env-defaults for consistency
# Disable "exit on error" so we can capture the error code | ||
set +e | ||
exec_as_redmine bundle exec rake db:create >/dev/null | ||
res=$? | ||
# Restore "exit on error" | ||
set -e | ||
|
||
if [[ 0 -ne $res ]] ; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note shellcheck will tell you its better to if check the command directly instead of storing the results. I think this also would mean we don't have to disable exit on error.
# Disable "exit on error" so we can capture the error code | |
set +e | |
exec_as_redmine bundle exec rake db:create >/dev/null | |
res=$? | |
# Restore "exit on error" | |
set -e | |
if [[ 0 -ne $res ]] ; then | |
if ! exec_as_redmine bundle exec rake db:create >/dev/null | |
then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note shellcheck will tell you its better to if check the command directly instead of storing the results. I think this also would mean we don't have to disable exit on error.
I wanted to retain the exit value from rake db:create
, since I don't know the range of non-zero values that it can produce. The only way I know of doing that is to do the res=$?
, which requires disabling "exit-on-error".
I'm happy to change it you are ok with returning a fixed value, e.g.:
if ! exec_as_redmine bundle exec rake db:create >/dev/null ; then
echo <<-EOM
Failed to create db. If db exists, and user (or role) exists and has access to db but no permission to create databases, set:
-----------------------
DB_CREATE=false
-----------------------
EOM
# FWIW, using "return" here would be consistent a similar use of "exec_as_redmine' in "redmine_check_database_connection"
exit 1
fi
Added a
DB_CREATE
option (defaulttrue
) to allow skipping the call tobundle exec rake db:create
. Particularly important for connecting to databases where the user doesn't have permission to create databases.