Add support for populating test data during migration testing

This change ensures that the tables in the database during migration have at least one row of "real" data, which should help catch issues in the future where we forget to set column defaults and other such schema oversights that can only be truly tested with non-empty tables

Fixes https://jira.coreos.com/browse/QUAY-913
This commit is contained in:
Joseph Schorr 2018-05-07 16:45:57 +03:00
parent c92c0ca5e1
commit f6ff0d6ca0
41 changed files with 653 additions and 86 deletions

View file

@ -8,7 +8,7 @@ PGSQL_CONFIG_OVERRIDE="{\"DB_URI\":\"postgresql://postgres@$DOCKER_IP/genschema\
up_mysql() {
# Run a SQL database on port 3306 inside of Docker.
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql:5.7
echo 'Sleeping for 25...'
sleep 25
@ -18,8 +18,8 @@ up_mysql() {
}
down_mysql() {
docker kill mysql
docker rm -v mysql
docker kill mysql || true
docker rm -v mysql || true
}
up_mariadb() {
@ -34,8 +34,8 @@ up_mariadb() {
}
down_mariadb() {
docker kill mariadb
docker rm -v mariadb
docker kill mariadb || true
docker rm -v mariadb || true
}
up_percona() {
@ -50,8 +50,8 @@ up_percona() {
}
down_percona() {
docker kill percona
docker rm -v percona
docker kill percona || true
docker rm -v percona || true
}
up_postgres() {
@ -67,8 +67,8 @@ up_postgres() {
}
down_postgres() {
docker kill postgres
docker rm -v postgres
docker kill postgres || true
docker rm -v postgres || true
}
gen_migrate() {
@ -83,14 +83,19 @@ gen_migrate() {
test_migrate() {
# Generate a database with the schema as defined by the existing alembic model.
echo '> Running upgrade'
QUAY_OVERRIDE_CONFIG=$1 PYTHONPATH=. alembic upgrade head
TEST_MIGRATE=true QUAY_OVERRIDE_CONFIG=$1 PYTHONPATH=. alembic upgrade head
# Downgrade to verify it works in both directions.
echo '> Running downgrade'
COUNT=`ls data/migrations/versions/*.py | wc -l | tr -d ' '`
QUAY_OVERRIDE_CONFIG=$1 PYTHONPATH=. alembic downgrade "-$COUNT"
TEST_MIGRATE=true QUAY_OVERRIDE_CONFIG=$1 PYTHONPATH=. alembic downgrade "-$COUNT"
}
down_mysql
down_postgres
down_mariadb
down_percona
# Test (and generate, if requested) via MySQL.
echo '> Starting MySQL'
up_mysql