]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3788] fixed upgrade scripts
authorRazvan Becheriu <razvan@isc.org>
Sat, 22 Mar 2025 08:51:36 +0000 (10:51 +0200)
committerRazvan Becheriu <razvan@isc.org>
Mon, 24 Mar 2025 09:30:25 +0000 (11:30 +0200)
src/bin/admin/tests/mysql_tests.sh.in
src/bin/admin/tests/pgsql_tests.sh.in
src/share/database/scripts/mysql/upgrade_022_to_023.sh.in
src/share/database/scripts/pgsql/upgrade_022_to_023.sh.in
src/share/database/scripts/utils/are-scripts-in-sync.py

index 7910291f03a6ba59eb9de3a4ab8731179b2550ef..3c6513da32a49e6dcb9a731b1395893865fc235a 100755 (executable)
@@ -148,20 +148,16 @@ mysql_db_version_test() {
         "${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}"
     assert_eq 1 "${EXIT_CODE}" "schema_version table still exists. (expected %d, exit code %d)"
 
-    # Ok, now let's create a version 1.7
+    # Create the database
     run_command \
-        mysql -u"${db_user}" -p"${db_password}" "${db_name}" -e \
-'CREATE TABLE schema_version (
-    version INT PRIMARY KEY NOT NULL,
-    minor INT
-);
-INSERT INTO schema_version VALUES (1, 7)'
-    assert_eq 0 "${EXIT_CODE}" "schema_version table cannot be created. (expected %d, exit code %d)"
+        "${kea_admin}" db-init mysql -u "${db_user}" -p "${db_password}" -n "${db_name}" -d "${db_scripts_dir}"
+    assert_eq 0 "${EXIT_CODE}" "cannot initialize the database, expected exit code: %d, actual: %d"
 
+    # Verify that kea-admin db-version returns the latest version.
     run_command \
         "${kea_admin}" db-version mysql -u "${db_user}" -p "${db_password}" -n "${db_name}"
     version="${OUTPUT}"
-    assert_str_eq "1.7" "${version}" "Expected kea-admin to return %s, returned value was %s"
+    assert_str_eq "29.0" "${version}" "Expected kea-admin to return %s, returned value was %s"
 
     # Let's wipe the whole database
     mysql_wipe
@@ -962,6 +958,11 @@ mysql_upgrade_24_to_25_test() {
 }
 
 mysql_upgrade_25_to_26_test() {
+    qry="select name from option_def_data_type where id = 3"
+    run_command \
+        mysql_execute "${qry}"
+    assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
+    assert_str_eq 'int8' "${OUTPUT}" "${qry}: expected output %s, returned %s"
 
     # client_classes been added to dhcp4_options
     check_table_column client_classes dhcp4_options
@@ -1884,7 +1885,7 @@ mysql_lease4_upload_test() {
         input_file_cp=""
     fi
 
-    # Wipe the whole database.
+    # Let's wipe the whole database.
     mysql_wipe
 
     # Clean up any test files left from prior failed runs unless -y was provided in which case
@@ -1935,7 +1936,7 @@ mysql_lease4_upload_test() {
     rm -f "${output_file}"
     rm -f "${output_file}.tmp"
 
-    # Wipe the whole database.
+    # Let's wipe the whole database.
     mysql_wipe
 
     test_finish 0
@@ -1955,7 +1956,7 @@ mysql_lease6_upload_test() {
         input_file_cp=""
     fi
 
-    # Wipe the whole database.
+    # Let's wipe the whole database.
     mysql_wipe
 
     # Clean up any test files left from prior failed runs unless -y was provided in which case
@@ -2006,7 +2007,7 @@ mysql_lease6_upload_test() {
     rm -f "${output_file}"
     rm -f "${output_file}.tmp"
 
-    # Wipe the whole database.
+    # Let's wipe the whole database.
     mysql_wipe
 
     test_finish 0
index b9475e7e3015244419fce6526190016a7aeed85f..f90638ec0b6ba65711c3c937bbb28fdb2e352d50 100755 (executable)
@@ -140,7 +140,7 @@ pgsql_db_init_test() {
 pgsql_db_version_test() {
     test_start "pgsql.db-version"
 
-    # Wipe the whole database
+    # Let's wipe the whole database
     pgsql_wipe
 
     # Do not create any table so db-version will raise an error
@@ -1055,6 +1055,12 @@ pgsql_upgrade_24_to_25_test() {
 }
 
 pgsql_upgrade_25_to_26_test() {
+    qry="select name from option_def_data_type where id = 3"
+    run_command \
+        pgsql_execute "${qry}"
+    assert_eq 0 "${EXIT_CODE}" "${qry}. (expected status code %d, returned %d)"
+    assert_str_eq 'int8' "${OUTPUT}" "${qry}: expected output %s, returned %s"
+
     # client_classes been added to dhcp4_options
     check_table_column client_classes dhcp4_options
 
@@ -1126,7 +1132,7 @@ pgsql_upgrade_28_to_29_test() {
 pgsql_upgrade_test() {
     test_start "pgsql.upgrade"
 
-    # Wipe the whole database
+    # Let's wipe the whole database
     pgsql_wipe
 
     # Initialize database to schema 1.0.
@@ -1390,7 +1396,7 @@ pgsql_lease4_upload_test() {
         input_file_cp=""
     fi
 
-    # Wipe the whole database.
+    # Let's wipe the whole database.
     pgsql_wipe
 
     # Clean up any test files left from prior failed runs unless -y was provided in which case
@@ -1439,7 +1445,7 @@ pgsql_lease4_upload_test() {
     rm -f "${output_file}"
     rm -f "${output_file}.tmp"
 
-    # Wipe the whole database.
+    # Let's wipe the whole database.
     pgsql_wipe
 
     test_finish 0
@@ -1458,7 +1464,7 @@ pgsql_lease6_upload_test() {
         input_file_cp=""
     fi
 
-    # Wipe the whole database.
+    # Let's wipe the whole database.
     pgsql_wipe
 
     # Clean up any test files left from prior failed runs unless -y was provided in which case
@@ -1507,7 +1513,7 @@ pgsql_lease6_upload_test() {
     rm -f "${output_file}"
     rm -f "${output_file}.tmp"
 
-    # Wipe the whole database.
+    # Let's wipe the whole database.
     pgsql_wipe
 
     test_finish 0
index 2abfd960cf40c4f33806329c97370f126e3c6694..3445aa8c0408656d712354837a9a6aec3dd1e651 100755 (executable)
@@ -28,7 +28,7 @@ fi
 
 # Check version.
 version=$(mysql_version "${@}")
-if [ "$version" != "22.0" ] && [ "$version" != "22.1" ]; then
+if [ "$version" != "22.0" ] && [ "$version" != "22.1" ] && [ "$version" != "22.2" ]; then
     printf 'This script upgrades 22.0 or 22.1 to 23.0. '
     printf 'Reported version is %s. Skipping upgrade.\n' "${version}"
     exit 0
index bc189726327298310d84476b17a3ed38d81fefe3..c224c8fba0b06ada523e4e8e415b8f247fab1761 100755 (executable)
@@ -28,7 +28,7 @@ fi
 
 VERSION=$(pgsql_version "$@")
 
-if [ "$VERSION" != "22.0" ] && [ "$VERSION" != "22.1" ]; then
+if [ "$VERSION" != "22.0" ] && [ "$VERSION" != "22.1" ] && [ "$VERSION" != "22.2" ]; then
     printf 'This script upgrades 22.0 or 22.1 to 23.0. '
     printf 'Reported version is %s. Skipping upgrade.\n' "${VERSION}"
     exit 0
index 7b42f9b92573873eab4ae9c775f1af7f18cae3fe..07f7d7842ef599eb7fbf9bdb75bc029d177f6f1f 100755 (executable)
@@ -217,7 +217,15 @@ def find_files_in_same_directory_starting_with(file, startswith):
         matches = re.search('^' + dirname + '/' + startswith + '.*$', i)
         if matches is not None:
             files.append(matches.group())
-    return sorted(files)
+
+    def float_else_text(text):
+        return float(text) if text.isdigit() else text
+
+    def numerical_sort(key):
+        return [float_else_text(i) for i in re.split(r'([0-9]+\.?[0-9]*)', key)]
+
+    files.sort(key=lambda filename: numerical_sort(filename.split('_')[-1]))
+    return files
 
 
 def find_last_file_in_same_directory_starting_with(file: str, startswith: str):