Skip to content

Commit

Permalink
Merge pull request #7579 from mackdk/improve-sql-scripts-execution-fo…
Browse files Browse the repository at this point in the history
…r-acceptance-tests

Run the updates based on the installed version
  • Loading branch information
jordimassaguerpla authored Sep 22, 2023
2 parents e34c785 + 0de8e8b commit 374f288
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 7 additions & 6 deletions testsuite/podman_runner/07_manager_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ sudo -i podman exec uyuni-server-all-in-one-test bash -c "/usr/bin/spacewalk-sch

# Make sure latest sql migration scripts have been executed for both the main and the reporting database
available_schemas=("spacewalk" "reportdb")
for schema in ${available_schemas[@]}; do
specfile=$(find ${src_dir}/schema/${schema}/ -name *.spec)
# Use Perl extended regexp and look-around assertions to extract only the values from the spec properties
schema_name=$(grep -oP "Name:\s+\K(.*)$" ${specfile})
schema_version=$(grep -oP "Version:\s+\K(.*)$" ${specfile})
for schema in "${available_schemas[@]}"; do
specfile=$(find "${src_dir}/schema/${schema}/" -name '*.spec')
# Get the package name from the spec using Perl extended regexp and look-around assertions to extract only its value
schema_name=$(grep -oP "Name:\s+\K(.*)$" "${specfile}")
# Check the version of the package installed in the podman container
schema_version=$(sudo -i podman exec uyuni-server-all-in-one-test rpm -q --queryformat '%{version}' "${schema_name}")

# Run the missing migrations and only those, to ensure no script is out of place
sudo -i podman exec uyuni-server-all-in-one-test bash -c "/testsuite/podman_runner/run_db_migrations.sh ${schema_name} ${schema_version}"
done

5 changes: 4 additions & 1 deletion testsuite/podman_runner/run_db_migrations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ else
exit 1
fi

for i in $(find ${upgrade_dir} -name "$1-$2-to-*"); do
# Including all sub-folders of the upgrade dir that comes after the one called "${schema_name}-${schema_version}-to-..."
# This should make sure we apply all the scripts meant to be executed on top of the current schema version.
# It probably won't happen often that we have multiple pending directories, but it could happen in case of re-tagging
for i in $(find ${upgrade_dir} -name "$1-*-to-*" | sed -n "/$1-$2-to-.*$/,$ p"); do
echo $(basename $i)
for j in $(find $i -name *.sql); do
echo -e "\t$(basename $j)"; spacewalk-sql ${additional_params} $j | sed 's/^/\t\t/';
Expand Down

0 comments on commit 374f288

Please sign in to comment.