helm: Convert the anonymous and superuser token to values in values.yaml
[arvados-k8s.git] / arvados / config / sso / 90-init-db.sh
1 #!/bin/bash
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: Apache-2.0
5
6 set -e
7
8 prepare_database() {
9   RAILSPKG_DATABASE_LOAD_TASK="$1"
10   DB_MIGRATE_STATUS=$($COMMAND_PREFIX bundle exec rake db:migrate:status 2>&1 || true)
11   if echo "$DB_MIGRATE_STATUS" | grep -qF 'Schema migrations table does not exist yet.'; then
12       # The database exists, but the migrations table doesn't.
13       bundle exec rake "$RAILSPKG_DATABASE_LOAD_TASK" db:seed
14   elif echo "$DB_MIGRATE_STATUS" | grep -q '^database: '; then
15       bundle exec rake db:migrate
16   elif echo "$DB_MIGRATE_STATUS" | grep -q 'database .* does not exist'; then
17       bundle exec rake db:setup
18   else
19     echo "Warning: Database is not ready to set up." >&2
20     exit 1
21   fi
22 }
23
24 prepare_database "db:schema:load"