Skip to content

Commit

Permalink
Test pgautoupgrade container using AdventureWorks database
Browse files Browse the repository at this point in the history
  • Loading branch information
andyundso committed Oct 22, 2024
1 parent e08fc14 commit a92fa91
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 467 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pgstuff
test/postgres-data
.idea

test/AdventureWorks.sql
test/AdventureWorks.tar.xz
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,14 @@ To run the tests, use:
$ make test
```

The test script creates an initial PostgreSQL database for
Redash using an older PG version, then starts Redash using
the above "automatic updating" PostgreSQL image to update
the database to the latest PostgreSQL version.
The test script imports the AdventureWorks database (ported from Microsoft
land) into an older PG version, then starts the pgautoupgrade container to
update the database to the latest PostgreSQL version.

It then checks that the database files were indeed updated
to the newest PostgreSQL release, and outputs an obvious
SUCCESS/FAILURE message for that loop.

The test runs in a loop, testing (in sequence) upgrades from
PostgreSQL versions 9.5, 9.6, 10.x, 11.x, 12.x, 13.x, 14.x
and 15.x.
PostgreSQL versions 9.5, 9.6, 10.x, 11.x, 12.x, 13.x, 14.x, 15.x., 16.x and
17.x.
25 changes: 20 additions & 5 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ test_down() {
docker compose -f test/docker-compose-pgauto.yml down
}

import_adventure_works() {
# Create the PostgreSQL database using a specific version of PostgreSQL
docker compose -f "docker-compose-pg${VERSION}.yml" up -d --wait

# Create a database and import AdventureWorks
docker compose -f "docker-compose-pg${VERSION}.yml" exec postgres createdb -U postgres AdventureWorks
cat AdventureWorks.sql | docker compose -f "docker-compose-pg${VERSION}.yml" exec --no-TTY postgres psql -U postgres -d AdventureWorks > /dev/null 2>&1

# Shutdown the existing version
docker compose -f "docker-compose-pg${VERSION}.yml" down -v
}

test_run() {
VERSION=$1
TARGET=$2
Expand All @@ -36,10 +48,9 @@ test_run() {
sudo rm -rf postgres-data
fi

# Create the PostgreSQL database using a specific version of PostgreSQL
docker compose -f "docker-compose-pg${VERSION}.yml" run --rm server create_db
import_adventure_works

# Start Redash normally, using an "autoupdate" version of PostgreSQL
# Start pgautoupgrade container
TARGET_TAG="${TARGET}-${FLAVOR}" docker compose -f docker-compose-pgauto.yml up --wait -d

# Verify the PostgreSQL data files are now the target version
Expand All @@ -62,8 +73,7 @@ test_run() {
##
banner '-' "Testing 'one shot' automatic upgrade mode for PostgreSQL ${VERSION} to ${TARGET}"

# Create the PostgreSQL database using a specific version of PostgreSQL
docker compose -f "docker-compose-pg${VERSION}.yml" run --rm server create_db
import_adventure_works

# Shut down all of the containers
docker compose -f "docker-compose-pg${VERSION}.yml" down --remove-orphans
Expand Down Expand Up @@ -102,6 +112,11 @@ fi
# Change into the test directory
cd test || exit 1

echo "Downloading and extracting the AdventureWork database ..."
rm -rf AdventureWorks.tar.xz AdventureWorks.sql
curl -L -o AdventureWorks.tar.xz "https://github.com/pgautoupgrade/AdventureWorks-for-Postgres/raw/refs/heads/master/AdventureWorks.tar.xz"
tar -xf AdventureWorks.tar.xz

for version in "${PG_VERSIONS[@]}"; do
# Only test if the version is less than the latest version
if [[ $(echo "$version < $PGTARGET" | bc) -eq 1 ]]; then
Expand Down
6 changes: 0 additions & 6 deletions test/.env
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
# The values below are useful for testing this repo with
#REDASH_LOG_LEVEL=INFO
REDASH_COOKIE_SECRET=HKuj2aZx7vRQXghnegXY0tDZWPS493F5
REDASH_SECRET_KEY=SHGVxI1Yecfz9k7xjwMnF0hCtwh04dFk
PYTHONUNBUFFERED=0
REDASH_REDIS_URL=redis://redis:6379/0
POSTGRES_PASSWORD=FmTKs5vX52ufKR1rd8tn4MoSP7zvCJwb
REDASH_DATABASE_URL=postgresql://postgres:FmTKs5vX52ufKR1rd8tn4MoSP7zvCJwb@postgres/postgres
45 changes: 0 additions & 45 deletions test/docker-compose-pg10.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,4 @@
x-redash-service: &redash-service
image: redash/redash:10.1.0.b50633
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
env_file: .env
restart: always
services:
server:
<<: *redash-service
command: server
ports:
- "127.0.0.1:5000:5000"
environment:
REDASH_WEB_WORKERS: 22
scheduler:
<<: *redash-service
command: scheduler
scheduled_worker:
<<: *redash-service
command: worker
environment:
QUEUES: "scheduled_queries,schemas"
WORKERS_COUNT: 2
adhoc_worker:
<<: *redash-service
command: worker
environment:
QUEUES: "queries"
WORKERS_COUNT: 2
redis:
image: redis:7-alpine
restart: always
healthcheck:
test: redis-cli -h 127.0.0.1 ping | grep -q PONG
interval: 10s
timeout: 5s
retries: 5
postgres:
image: postgres:10-alpine
env_file: .env
Expand All @@ -49,9 +10,3 @@ services:
interval: 10s
timeout: 5s
retries: 5
worker:
<<: *redash-service
command: worker
environment:
QUEUES: "periodic emails default"
WORKERS_COUNT: 2
45 changes: 0 additions & 45 deletions test/docker-compose-pg11.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,4 @@
x-redash-service: &redash-service
image: redash/redash:10.1.0.b50633
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
env_file: .env
restart: always
services:
server:
<<: *redash-service
command: server
ports:
- "127.0.0.1:5000:5000"
environment:
REDASH_WEB_WORKERS: 22
scheduler:
<<: *redash-service
command: scheduler
scheduled_worker:
<<: *redash-service
command: worker
environment:
QUEUES: "scheduled_queries,schemas"
WORKERS_COUNT: 2
adhoc_worker:
<<: *redash-service
command: worker
environment:
QUEUES: "queries"
WORKERS_COUNT: 2
redis:
image: redis:7-alpine
restart: always
healthcheck:
test: redis-cli -h 127.0.0.1 ping | grep -q PONG
interval: 10s
timeout: 5s
retries: 5
postgres:
image: postgres:11-alpine
env_file: .env
Expand All @@ -49,9 +10,3 @@ services:
interval: 10s
timeout: 5s
retries: 5
worker:
<<: *redash-service
command: worker
environment:
QUEUES: "periodic emails default"
WORKERS_COUNT: 2
45 changes: 0 additions & 45 deletions test/docker-compose-pg12.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,4 @@
x-redash-service: &redash-service
image: redash/redash:10.1.0.b50633
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
env_file: .env
restart: always
services:
server:
<<: *redash-service
command: server
ports:
- "127.0.0.1:5000:5000"
environment:
REDASH_WEB_WORKERS: 22
scheduler:
<<: *redash-service
command: scheduler
scheduled_worker:
<<: *redash-service
command: worker
environment:
QUEUES: "scheduled_queries,schemas"
WORKERS_COUNT: 2
adhoc_worker:
<<: *redash-service
command: worker
environment:
QUEUES: "queries"
WORKERS_COUNT: 2
redis:
image: redis:7-alpine
restart: always
healthcheck:
test: redis-cli -h 127.0.0.1 ping | grep -q PONG
interval: 10s
timeout: 5s
retries: 5
postgres:
image: postgres:12-alpine
env_file: .env
Expand All @@ -49,9 +10,3 @@ services:
interval: 10s
timeout: 5s
retries: 5
worker:
<<: *redash-service
command: worker
environment:
QUEUES: "periodic emails default"
WORKERS_COUNT: 2
45 changes: 0 additions & 45 deletions test/docker-compose-pg13.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,4 @@
x-redash-service: &redash-service
image: redash/redash:10.1.0.b50633
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
env_file: .env
restart: always
services:
server:
<<: *redash-service
command: server
ports:
- "127.0.0.1:5000:5000"
environment:
REDASH_WEB_WORKERS: 22
scheduler:
<<: *redash-service
command: scheduler
scheduled_worker:
<<: *redash-service
command: worker
environment:
QUEUES: "scheduled_queries,schemas"
WORKERS_COUNT: 2
adhoc_worker:
<<: *redash-service
command: worker
environment:
QUEUES: "queries"
WORKERS_COUNT: 2
redis:
image: redis:7-alpine
restart: always
healthcheck:
test: redis-cli -h 127.0.0.1 ping | grep -q PONG
interval: 10s
timeout: 5s
retries: 5
postgres:
image: postgres:13-alpine
env_file: .env
Expand All @@ -49,9 +10,3 @@ services:
interval: 10s
timeout: 5s
retries: 5
worker:
<<: *redash-service
command: worker
environment:
QUEUES: "periodic emails default"
WORKERS_COUNT: 2
45 changes: 0 additions & 45 deletions test/docker-compose-pg14.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,4 @@
x-redash-service: &redash-service
image: redash/redash:10.1.0.b50633
depends_on:
redis:
condition: service_healthy
postgres:
condition: service_healthy
env_file: .env
restart: always
services:
server:
<<: *redash-service
command: server
ports:
- "127.0.0.1:5000:5000"
environment:
REDASH_WEB_WORKERS: 22
scheduler:
<<: *redash-service
command: scheduler
scheduled_worker:
<<: *redash-service
command: worker
environment:
QUEUES: "scheduled_queries,schemas"
WORKERS_COUNT: 2
adhoc_worker:
<<: *redash-service
command: worker
environment:
QUEUES: "queries"
WORKERS_COUNT: 2
redis:
image: redis:7-alpine
restart: always
healthcheck:
test: redis-cli -h 127.0.0.1 ping | grep -q PONG
interval: 10s
timeout: 5s
retries: 5
postgres:
image: postgres:14-alpine
env_file: .env
Expand All @@ -49,9 +10,3 @@ services:
interval: 10s
timeout: 5s
retries: 5
worker:
<<: *redash-service
command: worker
environment:
QUEUES: "periodic emails default"
WORKERS_COUNT: 2
Loading

0 comments on commit a92fa91

Please sign in to comment.