File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+ set -x
3+ set -eo pipefail
4+
5+ # Use Podman if Docker is unavailable
6+ if command -v docker & > /dev/null; then
7+ CONTAINER_RUNTIME=" docker"
8+ else
9+ CONTAINER_RUNTIME=" podman"
10+ fi
11+
12+ $CONTAINER_RUNTIME run \
13+ --env POSTGRES_HOST_AUTH_METHOD=trust \
14+ --publish " 127.0.0.1:5432" :5432 \
15+ --detach \
16+ --name postgres_container \
17+ docker.io/library/postgres
18+
19+ # Check if .env file exists, if not create it with the DATABASE_URL
20+ ENV_FILE=" .env"
21+ DATABASE_URL=
" postgres://[email protected] :5432/postgres" 22+
23+ if [ ! -f " $ENV_FILE " ]; then
24+ echo " Creating $ENV_FILE "
25+ echo " DATABASE_URL=$DATABASE_URL " > " $ENV_FILE "
26+ else
27+ if grep -q " ^DATABASE_URL=" " $ENV_FILE " ; then
28+ echo " WARNING: Updating DATABASE_URL in $ENV_FILE "
29+ echo " Backing up .env to .env.bak ..."
30+ sed -i.bak " s|^DATABASE_URL=.*|DATABASE_URL=$DATABASE_URL |" " $ENV_FILE "
31+ else
32+ echo " Adding DATABASE_URL to $ENV_FILE "
33+ echo " DATABASE_URL=$DATABASE_URL " >> " $ENV_FILE "
34+ fi
35+ fi
36+
37+ sleep 1
38+ sqlx migrate run
You can’t perform that action at this time.
0 commit comments