Skip to content

Commit bf0c56f

Browse files
committed
Ensure postgres is running before running SQL
1 parent 09ce48f commit bf0c56f

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

tasks/reset.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,23 @@
66

77
set -euxo pipefail
88

9+
fail_if_postgres_not_running () {
10+
containers=$(docker ps --filter "name=${container_name}" --quiet)
11+
if [ -z "${containers}" ]; then
12+
echo "error: Docker container for PostgreSQL is not running"
13+
echo "error: Try running 'mise run postgres:up ${container_name}' to start the container"
14+
exit 65
15+
fi
16+
}
17+
918
POSTGRES_VERSION=${usage_postgres}
1019

1120
connection_url=postgresql://${POSTGRES_USER:-$USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
1221
container_name=postgres-${POSTGRES_VERSION}
1322

23+
# Setup
24+
fail_if_postgres_not_running
25+
1426
# Uninstall
1527
cat release/cipherstash-encrypt-uninstall.sql | docker exec -i ${container_name} psql ${connection_url} -f-
1628

tasks/test.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ set -euo pipefail
1010

1111
POSTGRES_VERSION=${usage_postgres}
1212

13-
mise run build
14-
mise run reset --postgres ${POSTGRES_VERSION}
15-
1613
connection_url=postgresql://${POSTGRES_USER:-$USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
1714
container_name=postgres-${POSTGRES_VERSION}
1815

16+
fail_if_postgres_not_running () {
17+
containers=$(docker ps --filter "name=${container_name}" --quiet)
18+
if [ -z "${containers}" ]; then
19+
echo "error: Docker container for PostgreSQL is not running"
20+
echo "error: Try running 'mise run postgres:up ${container_name}' to start the container"
21+
exit 65
22+
fi
23+
}
24+
1925
run_test () {
2026
echo
2127
echo '###############################################'
@@ -25,6 +31,11 @@ run_test () {
2531
cat $1 | docker exec -i ${container_name} psql $connection_url -f-
2632
}
2733

34+
# setup
35+
fail_if_postgres_not_running
36+
mise run build
37+
mise run reset --postgres ${POSTGRES_VERSION}
38+
2839
# tests
2940
run_test tests/core.sql
3041
run_test tests/core-functions.sql

0 commit comments

Comments
 (0)