Skip to content

Commit

Permalink
Update both main and reportdb databases, using only upgrade script fo…
Browse files Browse the repository at this point in the history
…r the new version
  • Loading branch information
mackdk committed Aug 4, 2023
1 parent 58ed9ea commit 0cfe98b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
17 changes: 15 additions & 2 deletions testsuite/podman_runner/07_manager_setup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#!/bin/bash
set -xe

src_dir=$(cd $(dirname "$0")/../.. && pwd -P)

sudo -i podman exec uyuni-server-all-in-one-test bash -c "/usr/lib/susemanager/bin/mgr-setup -l /var/log/susemanager_setup.log -s"
sudo -i podman exec uyuni-server-all-in-one-test bash -c "/usr/bin/spacewalk-schema-upgrade -y"
# Make sure latest sql migration scripts have been executed
sudo -i podman exec uyuni-server-all-in-one-test bash -c "/testsuite/podman_runner/run_db_migrations.sh"

# 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})

sudo -i podman exec uyuni-server-all-in-one-test bash -c "/testsuite/podman_runner/run_db_migrations.sh ${schema_name} ${schema_version}"
done

31 changes: 27 additions & 4 deletions testsuite/podman_runner/run_db_migrations.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
#!/bin/bash -e
for i in $(ls /etc/sysconfig/rhn/schema-upgrade/ | tail -n1);do
for j in $(ls /etc/sysconfig/rhn/schema-upgrade/$i);do
echo $i;spacewalk-sql /etc/sysconfig/rhn/schema-upgrade/$i/$j;

if [ $# -ne 2 ];
then
echo "Usage: $0 <schema_name> <schema_version>"
echo "where"
echo " schema_name name of the schema to update (susemanager-schema or uyuni-reportdb-schema)"
echo " schema_version version of the schema currently installed"
exit 1
fi

if [[ "$1" == "susemanager-schema" ]];
then
upgrade_dir="/etc/sysconfig/rhn/schema-upgrade/"
additional_params=""
elif [[ "$1" == "uyuni-reportdb-schema" ]];
then
upgrade_dir="/etc/sysconfig/rhn/reportdb-schema-upgrade/"
additional_params="--reportdb"
else
echo "Unknown schema $1. Use either susemanager-schema or uyuni-reportdb-schema."
exit 1
fi

for i in $(find ${upgrade_dir} -name "$1-$2-to-*"); 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/';
done;
done

0 comments on commit 0cfe98b

Please sign in to comment.