Debian Codegraph @

entrypoint.sh

raw
1 #!/bin/bash
2 # Copyright 2023 The Archivista Contributors
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 ARCHIVISTA_ENABLE_SQL_STORE=$(echo ${ARCHIVISTA_ENABLE_SQL_STORE} | tr '[:lower:]' '[:upper:]')
17
18 if [ "${ARCHIVISTA_ENABLE_SQL_STORE}" = "FALSE" ]; then
19 echo "Skipping migrations"
20 else
21 if [[ -z $ARCHIVISTA_SQL_STORE_BACKEND ]]; then
22 SQL_TYPE="MYSQL"
23 else
24 SQL_TYPE=$(echo "$ARCHIVISTA_SQL_STORE_BACKEND" | tr '[:lower:]' '[:upper:]')
25 fi
26 case $SQL_TYPE in
27 MYSQL*)
28 if [[ -z $ARCHIVISTA_SQL_STORE_CONNECTION_STRING ]]; then
29 ARCHIVISTA_SQL_STORE_CONNECTION_STRING="root:example@db/testify"
30 fi
31 echo "Running migrations for MySQL"
32 DB_URL="mysql://${ARCHIVISTA_SQL_STORE_CONNECTION_STRING}"
33 if [[ "$SQL_TYPE" == *_RDS_IAM ]]; then
34 DB_URL=$(/bin/archivistactl iam "${SQL_TYPE}" "${DB_URL}")
35 fi
36 atlas migrate apply --dir "file:///archivista/migrations/mysql" --url "${DB_URL}"
37 atlas_rc=$?
38 ;;
39 PSQL*)
40 echo "Running migrations for Postgres"
41 DB_URL="${ARCHIVISTA_SQL_STORE_CONNECTION_STRING}"
42 if [[ "$SQL_TYPE" == *_RDS_IAM ]]; then
43 DB_URL=$(/bin/archivistactl iam "${SQL_TYPE}" "${DB_URL}")
44 fi
45 atlas migrate apply --dir "file:///archivista/migrations/pgsql" --url "${DB_URL}"
46 atlas_rc=$?
47 ;;
48 *)
49 echo "Unknown SQL backend: $ARCHIVISTA_SQL_STORE_BACKEND"
50 exit 1
51 ;;
52 esac
53
54 if [[ $atlas_rc -ne 0 ]]; then
55 echo "Failed to apply migrations"
56 exit 1
57 fi
58 fi
59
60 /bin/archivista