49 lines
1.8 KiB
Bash
Executable File
49 lines
1.8 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
image=${1:?usage: test-vector-migration-image.sh IMAGE [PLATFORM]}
|
|
platform=${2:-${PLATFORM:-linux/arm64}}
|
|
repo_root=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
|
|
slug=$$
|
|
network="thoth-vector-migration-$slug"
|
|
database="thoth-vector-db-$slug"
|
|
|
|
cleanup() {
|
|
docker rm --force "$database" >/dev/null 2>&1 || true
|
|
docker network rm "$network" >/dev/null 2>&1 || true
|
|
}
|
|
trap cleanup EXIT INT TERM
|
|
|
|
docker network create "$network" >/dev/null
|
|
docker run --detach --rm --platform "$platform" --name "$database" --network "$network" \
|
|
-e POSTGRES_DB=thoth -e POSTGRES_USER=thoth_admin -e POSTGRES_PASSWORD=test-only \
|
|
pgvector/pgvector:pg16 >/dev/null
|
|
|
|
attempt=0
|
|
until docker exec "$database" pg_isready -U thoth_admin -d thoth >/dev/null 2>&1; do
|
|
attempt=$((attempt + 1))
|
|
if [ "$attempt" -ge 30 ]; then
|
|
echo "pgvector test database did not become ready" >&2
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
database_url="postgresql+psycopg2://thoth_admin:test-only@$database:5432/thoth"
|
|
applied=$(docker run --rm --platform "$platform" --network "$network" \
|
|
--entrypoint /opt/venv/bin/tht -e THT_VECTOR_ADMIN_URL="$database_url" \
|
|
"$image" vector migrate --json)
|
|
status=$(docker run --rm --platform "$platform" --network "$network" \
|
|
--entrypoint /opt/venv/bin/tht -e THT_VECTOR_ADMIN_URL="$database_url" \
|
|
"$image" vector migrate --status --json)
|
|
|
|
expected_versions=$(find "$repo_root/harness/tht/migrations/vector" -type f -name '[0-9][0-9][0-9]_*.sql' \
|
|
| sed 's|.*/||; s|_.*||' \
|
|
| LC_ALL=C sort \
|
|
| awk 'BEGIN { separator = ""; printf "[" } { printf "%s\"%s\"", separator, $0; separator = ", " } END { print "]" }')
|
|
test "$expected_versions" != '[]'
|
|
expected="{\"applied\": $expected_versions, \"drifted\": [], \"pending\": []}"
|
|
test "$applied" = "$expected"
|
|
test "$status" = "$expected"
|
|
echo "core image vector migration discovery/status smoke passed"
|