Skip to content

Commit

Permalink
Add MariaDB migration testing (#2170)
Browse files Browse the repository at this point in the history
* update script to handle mariadb migration testing

* WIP

* reformat temporary script

* parameterize DB startup delay

* add a check for mysql vs mariadb

* try another way to isolate mariadb vs mysql

* try a different mariadb connection path

* Fix database connection URL in test-migrations.sh script

* Adjust settings for MySQL and MariaDB engines in migration script

* log values

* temporarily disable full CI runs for testing

* print values

* trying a different connection approach

* trying innodb

* Add support for MariaDB in primary key modification

* split mariadb from mysql db migration testing

* split mariadb from mysql db migration testing (core)

* Remove support for MariaDB and add version 0.53.1

* Split out mariadb from mysql in migration testing

* add latest zenml version

* Update migration testing scripts for different databases

* restore the CI to working state

* formatting

* use zenml init

* reformat yml

* revert to copier instantiation

* add conditional check for version >= 0.43.0

* compare set of vals instead of complicated semantic check

* remove extra cd

* update mariadb script

* add test flag to init command

* remove (extra) analytics opt-out

* Add additional template versions for testing migrations

* enable the CI again

* Add comment explaining pre-template-versions
  • Loading branch information
strickvl authored Jan 9, 2024
1 parent 8ae5a0c commit 1030551
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 9 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
with:
python-version: '3.9'
- name: Test migrations across versions
run: bash scripts/test-migrations.sh mysql
run: bash scripts/test-migrations-mysql.sh mysql
sqlite-db-migration-testing:
runs-on: ubuntu-dind-runners
steps:
Expand All @@ -49,13 +49,25 @@ jobs:
with:
python-version: '3.9'
- name: Test migrations across versions
run: bash scripts/test-migrations.sh sqlite
run: bash scripts/test-migrations-mysql.sh sqlite
mariadb-db-migration-testing:
runs-on: ubuntu-dind-runners
steps:
- name: Checkout code
uses: actions/checkout@v4.1.1
- name: Set up Python 3.9
uses: actions/setup-python@v4.8.0
with:
python-version: '3.9'
- name: Test migrations across versions
run: bash scripts/test-migrations-mariadb.sh
publish-python-package:
needs:
- setup-and-test
- mlstacks-compatibility-check
- sqlite-db-migration-testing
- mysql-db-migration-testing
- mariadb-db-migration-testing
uses: ./.github/workflows/publish_to_pypi.yml
secrets: inherit
wait-for-package-release:
Expand Down
86 changes: 86 additions & 0 deletions scripts/test-migrations-mariadb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash

DB="mariadb"
DB_STARTUP_DELAY=30 # Time in seconds to wait for the database container to start

function run_tests_for_version() {
set -e # Exit immediately if a command exits with a non-zero status
local VERSION=$1

echo "===== Testing version $VERSION ====="

mkdir test_starter
zenml init --template starter --path test_starter --template-with-defaults --test
cd test_starter

export ZENML_ANALYTICS_OPT_IN=false
export ZENML_DEBUG=true

echo "===== Installing sklearn integration ====="
zenml integration install sklearn -y

echo "===== Running starter template pipeline ====="
python3 run.py
# Add additional CLI tests here
zenml version

# Confirm DB works and is accessible
zenml pipeline runs list

cd ..
rm -rf test_starter
echo "===== Finished testing version $VERSION ====="
}

echo "===== Testing MariaDB ====="
# run a mariadb instance in docker
docker run --name mariadb -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password mariadb:10.6
# mariadb takes a while to start up
sleep $DB_STARTUP_DELAY

# List of versions to test
VERSIONS=("0.54.0")

# Start completely fresh
rm -rf ~/.config/zenml

for VERSION in "${VERSIONS[@]}"
do
set -e # Exit immediately if a command exits with a non-zero status
# Create a new virtual environment
python3 -m venv ".venv-$VERSION"
source ".venv-$VERSION/bin/activate"

# Install the specific version
pip3 install -U pip setuptools wheel
pip3 install "zenml[templates,server]==$VERSION"

zenml connect --url mysql://127.0.0.1/zenml --username root --password password

# Run the tests for this version
run_tests_for_version $VERSION

zenml disconnect
sleep 5

deactivate
done

# Test the most recent migration with MariaDB
echo "===== TESTING CURRENT BRANCH ====="
set -e
python3 -m venv ".venv-current-branch"
source ".venv-current-branch/bin/activate"

pip3 install -U pip setuptools wheel
pip3 install -e ".[templates,server]"
pip3 install importlib_metadata

zenml connect --url mysql://127.0.0.1/zenml --username root --password password

run_tests_for_version current_branch_mariadb

zenml disconnect
docker rm -f mariadb

deactivate
26 changes: 19 additions & 7 deletions scripts/test-migrations.sh → scripts/test-migrations-mysql.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash

DB="sqlite"
DB_STARTUP_DELAY=30 # Time in seconds to wait for the database container to start

if [ -z "$1" ]; then
echo "No argument passed, using default: $DB"
else
Expand All @@ -10,12 +12,20 @@ fi
function run_tests_for_version() {
set -e # Exit immediately if a command exits with a non-zero status
local VERSION=$1
# versions pre-templates and pre-init test flag
# (zenml init --test allows for a non-interactive init)
local PRE_TEMPLATE_VERSIONS=("0.40.0" "0.40.3" "0.41.0" "0.43.0" "0.44.1" "0.44.3" "0.45.2" "0.45.3" "0.45.4" "0.45.5" "0.45.6" "0.46.0" "0.47.0")

echo "===== Testing version $VERSION ====="
# Initialize zenml with the appropriate template
# hardcoded to 0.43.0 since this is the latest template-starter repo
# release tag
copier copy -l --trust -r release/0.43.0 https://github.com/zenml-io/template-starter.git test_starter

# Check if VERSION is in PRE_TEMPLATE_VERSIONS
if printf '%s\n' "${PRE_TEMPLATE_VERSIONS[@]}" | grep -q "^$VERSION$"; then
copier copy -l --trust -r release/0.43.0 https://github.com/zenml-io/template-starter.git test_starter
else
mkdir test_starter
zenml init --template starter --path test_starter --template-with-defaults --test
fi

cd test_starter

export ZENML_ANALYTICS_OPT_IN=false
Expand All @@ -37,17 +47,18 @@ function run_tests_for_version() {
echo "===== Finished testing version $VERSION ====="
}



if [ "$1" == "mysql" ]; then
echo "===== Testing MySQL ====="
# run a mysql instance in docker
docker run --name mysql -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password mysql:latest

# mysql takes a while to start up
sleep 30
sleep $DB_STARTUP_DELAY
fi

# List of versions to test
VERSIONS=("0.40.0" "0.40.3" "0.41.0" "0.43.0" "0.44.1" "0.44.3" "0.45.2" "0.45.3" "0.45.4" "0.45.5" "0.45.6" "0.46.0" "0.47.0" "0.50.0" "0.51.0" "0.52.0")
VERSIONS=("0.40.0" "0.40.3" "0.41.0" "0.43.0" "0.44.1" "0.44.3" "0.45.2" "0.45.3" "0.45.4" "0.45.5" "0.45.6" "0.46.0" "0.47.0" "0.50.0" "0.51.0" "0.52.0" "0.53.0" "0.53.1" "0.54.0")

# Start completely fresh
rm -rf ~/.config/zenml
Expand Down Expand Up @@ -95,6 +106,7 @@ done


# Test the most recent migration with MySQL
echo "===== TESTING CURRENT BRANCH ====="
set -e
python3 -m venv ".venv-current-branch"
source ".venv-current-branch/bin/activate"
Expand Down

0 comments on commit 1030551

Please sign in to comment.