db:prepare is running in issues, therefore use single db commands depending on the state of the database. tested with fresh deployment and migrations
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b5eec9e10f
commit
c9d4987e6f
@ -97,6 +97,7 @@ services:
|
|||||||
- loomio_files:/loomio/public/files
|
- loomio_files:/loomio/public/files
|
||||||
- loomio_plugins:/loomio/plugins/docker
|
- loomio_plugins:/loomio/plugins/docker
|
||||||
db:
|
db:
|
||||||
|
# loomio version upgrades and postgres version upgrade should not be performed at the same time.
|
||||||
image: pgautoupgrade/pgautoupgrade:17-debian
|
image: pgautoupgrade/pgautoupgrade:17-debian
|
||||||
networks:
|
networks:
|
||||||
- backend
|
- backend
|
||||||
|
@ -25,6 +25,7 @@ file_env "DEVISE_SECRET"
|
|||||||
file_env "SECRET_COOKIE_TOKEN"
|
file_env "SECRET_COOKIE_TOKEN"
|
||||||
file_env "POSTGRES_PASSWORD"
|
file_env "POSTGRES_PASSWORD"
|
||||||
file_env "SMTP_PASSWORD"
|
file_env "SMTP_PASSWORD"
|
||||||
|
export DB_HOST="db"
|
||||||
export DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db/${POSTGRES_DB}"
|
export DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db/${POSTGRES_DB}"
|
||||||
|
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
@ -36,8 +37,33 @@ else
|
|||||||
if [ "$TASK" = "worker" ]; then
|
if [ "$TASK" = "worker" ]; then
|
||||||
bundle exec sidekiq
|
bundle exec sidekiq
|
||||||
else
|
else
|
||||||
|
sudo apt update -y && sudo apt install -y postgresql-client
|
||||||
bundle install
|
bundle install
|
||||||
bundle exec rake db:prepare
|
|
||||||
|
# running this code instaed of db:prepare in docker_start.sh in loomio container
|
||||||
|
# as postgres container creates empty db, somehow db:prepare cannot cope.
|
||||||
|
# therefore we run db:setup or db:migrate individually
|
||||||
|
if PGPASSWORD=$(cat /run/secrets/db_password) psql -U "$POSTGRES_USER" -h "$DB_HOST" -lqt | cut -d \| -f 1 | grep -wq "$POSTGRES_DB"; then
|
||||||
|
echo "database '$POSTGRES_DB' exists."
|
||||||
|
|
||||||
|
# check if the database contains tables
|
||||||
|
TABLE_COUNT=$(PGPASSWORD=$(cat /run/secrets/db_password) psql -U "$POSTGRES_USER" -h "$DB_HOST" -d "$POSTGRES_DB" -t -c "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';")
|
||||||
|
|
||||||
|
if [ "$TABLE_COUNT" -eq 0 ]; then
|
||||||
|
echo "Database '$POSTGRES_DB' is empty, running db:setup."
|
||||||
|
bundle exec rake db:setup
|
||||||
|
#bundle exec rake db:schema:load
|
||||||
|
#bundle exec rake db:migrate
|
||||||
|
#bundle exec rake db:seed
|
||||||
|
else
|
||||||
|
echo "database '$POSTGRES_DB' not empty, running migrations."
|
||||||
|
bundle exec rake db:migrate
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "database '$POSTGRES_DB' does not exist, running db:setup."
|
||||||
|
bundle exec rake db:setup
|
||||||
|
fi
|
||||||
|
|
||||||
bundle exec puma -C config/puma.rb
|
bundle exec puma -C config/puma.rb
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user