Skip to content

Commit

Permalink
Add sequential migration tests for MariaDB and MySQL (#2502)
Browse files Browse the repository at this point in the history
* Add sequential migration tests for MariaDB and MySQL

* add semantic version order

* Update scripts/test-migrations-mariadb.sh

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* coderabbit suggestion for version comparison

* fresh start for sequential testing

* add missing code

* Remove unnecessary code in test-migrations-mariadb.sh

* list the drunk migration sequence

* focused testing

* add padding for logs

* always install importlib_metadata

* fix mysql db upgrades

* ruff

* fix mariadb too

* add mariadb for testing

* Auto-update of E2E template

* fix mariadb

* fresh mariadb

* fresh mysql

* fix final missing zenml

* CI as it should be

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: GitHub Actions <actions@github.com>
  • Loading branch information
3 people committed Mar 8, 2024
1 parent 712bedc commit 0b82d40
Show file tree
Hide file tree
Showing 2 changed files with 208 additions and 1 deletion.
86 changes: 85 additions & 1 deletion scripts/test-migrations-mariadb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,89 @@ run_tests_for_version current_branch_mariadb

zenml disconnect
docker rm -f mariadb

deactivate

# Function to compare semantic versions
function version_compare() {
IFS='.' read -ra ver1 <<< "$1"
IFS='.' read -ra ver2 <<< "$2"

for ((i=0; i<"${#ver1[@]}"; i++)); do
if (("${ver1[i]}" > "${ver2[i]}")); then
echo ">"
return
elif (("${ver1[i]}" < "${ver2[i]}")); then
echo "<"
return
fi
done

if ((${#ver1[@]} < ${#ver2[@]})); then
echo "<"
elif ((${#ver1[@]} > ${#ver2[@]})); then
echo ">"
else
echo "="
fi
}

# Start fresh again for this part
rm -rf ~/.config/zenml

# run a fresh 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

# Test sequential migrations across multiple versions
echo "===== TESTING SEQUENTIAL MIGRATIONS ====="
set -e
python3 -m venv ".venv-sequential-migrations"
source ".venv-sequential-migrations/bin/activate"

pip3 install -U pip setuptools wheel

# Randomly select versions for sequential migrations
MIGRATION_VERSIONS=()
while [ ${#MIGRATION_VERSIONS[@]} -lt 3 ]; do
VERSION=${VERSIONS[$RANDOM % ${#VERSIONS[@]}]}
if [[ ! " ${MIGRATION_VERSIONS[@]} " =~ " $VERSION " ]]; then
MIGRATION_VERSIONS+=("$VERSION")
fi
done

# Sort the versions based on semantic versioning rules
IFS=$'\n' MIGRATION_VERSIONS=($(sort -t. -k 1,1n -k 2,2n -k 3,3n <<<"${MIGRATION_VERSIONS[*]}"))

# Echo the sorted list of migration versions
echo "============================="
echo "TESTING MIGRATION_VERSIONS: ${MIGRATION_VERSIONS[@]}"
echo "============================="

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

# Install the specific version
pip3 install -U pip setuptools wheel

git checkout release/${MIGRATION_VERSIONS[$i]}
pip3 install -e ".[templates,server]"

export ZENML_ANALYTICS_OPT_IN=false
export ZENML_DEBUG=true

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

# Run the tests for this version
run_tests_for_version ${MIGRATION_VERSIONS[$i]}

zenml disconnect
sleep 5

deactivate
done

docker rm -f mariadb
123 changes: 123 additions & 0 deletions scripts/test-migrations-mysql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,126 @@ fi

deactivate

# Function to compare semantic versions
function version_compare() {
local regex="^([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(\\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?$"
local ver1="$1"
local ver2="$2"

if ! [[ $ver1 =~ $regex ]]; then
echo "First argument does not conform to semantic version format" >&2
return 1
fi

if ! [[ $ver2 =~ $regex ]]; then
echo "Second argument does not conform to semantic version format" >&2
return 1
fi

# Compare major, minor, and patch versions
IFS='.' read -ra ver1_parts <<< "$ver1"
IFS='.' read -ra ver2_parts <<< "$ver2"

for ((i=0; i<3; i++)); do
if ((ver1_parts[i] > ver2_parts[i])); then
echo ">"
return
elif ((ver1_parts[i] < ver2_parts[i])); then
echo "<"
return
fi
done

# Extend comparison to pre-release versions if necessary
# This is a simplified comparison that may need further refinement
if [[ -n ${ver1_parts[3]} && -z ${ver2_parts[3]} ]]; then
echo "<"
return
elif [[ -z ${ver1_parts[3]} && -n ${ver2_parts[3]} ]]; then
echo ">"
return
elif [[ -n ${ver1_parts[3]} && -n ${ver2_parts[3]} ]]; then
if [[ ${ver1_parts[3]} > ${ver2_parts[3]} ]]; then
echo ">"
return
elif [[ ${ver1_parts[3]} < ${ver2_parts[3]} ]]; then
echo "<"
return
fi
fi

echo "="
}

# Start fresh again for this part
rm -rf ~/.config/zenml

# fresh mysql for sequential testing
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 $DB_STARTUP_DELAY
fi

# Test sequential migrations across multiple versions
echo "===== TESTING SEQUENTIAL MIGRATIONS ====="
set -e
python3 -m venv ".venv-sequential-migrations"
source ".venv-sequential-migrations/bin/activate"

pip3 install -U pip setuptools wheel

# Randomly select versions for sequential migrations
MIGRATION_VERSIONS=()
while [ ${#MIGRATION_VERSIONS[@]} -lt 3 ]; do
VERSION=${VERSIONS[$RANDOM % ${#VERSIONS[@]}]}
if [[ ! " ${MIGRATION_VERSIONS[@]} " =~ " $VERSION " ]]; then
MIGRATION_VERSIONS+=("$VERSION")
fi
done

# Sort the versions based on semantic versioning rules
IFS=$'\n' MIGRATION_VERSIONS=($(sort -t. -k 1,1n -k 2,2n -k 3,3n <<<"${MIGRATION_VERSIONS[*]}"))

# Echo the sorted list of migration versions
echo "============================="
echo "TESTING MIGRATION_VERSIONS: ${MIGRATION_VERSIONS[@]}"
echo "============================="

for i in "${!MIGRATION_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

git checkout release/${MIGRATION_VERSIONS[$i]}
pip3 install -e ".[templates,server]"
# Handles unpinned sqlmodel dependency in older versions
pip3 install "sqlmodel==0.0.8" "bcrypt==4.0.1" importlib_metadata

# Get the major and minor version of Python
PYTHON_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')

if [ "$1" == "mysql" ]; then
zenml connect --url mysql://127.0.0.1/zenml --username root --password password
fi

# Run the tests for this version
run_tests_for_version ${MIGRATION_VERSIONS[$i]}

if [ "$1" == "mysql" ]; then
zenml disconnect
sleep 5
fi

deactivate
done

if [ "$1" == "mysql" ]; then
docker rm -f mysql
fi

0 comments on commit 0b82d40

Please sign in to comment.