Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sequential migration tests for MariaDB and MySQL #2502

Merged
merged 22 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading