From f5f56e1a1c4d9e9496fcb9d81131066a964ccd23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 14:15:43 +0200 Subject: Adding upstream version 2.4.1. Signed-off-by: Daniel Baumann --- src/share/database/scripts/mysql/wipe_data.sh.in | 122 +++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 src/share/database/scripts/mysql/wipe_data.sh.in (limited to 'src/share/database/scripts/mysql/wipe_data.sh.in') diff --git a/src/share/database/scripts/mysql/wipe_data.sh.in b/src/share/database/scripts/mysql/wipe_data.sh.in new file mode 100644 index 0000000..303e751 --- /dev/null +++ b/src/share/database/scripts/mysql/wipe_data.sh.in @@ -0,0 +1,122 @@ +#!/bin/sh + +# Copyright (C) 2019-2023 Internet Systems Consortium, Inc. ("ISC") +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# This script is primarily used for MySQL unit tests, which need to +# ensure an empty, but schema correct database for each test. It +# deletes ALL transient data from an existing Kea MySQL schema, +# including leases, reservations, etc... Use at your own peril. +# Reference tables will be left in-tact. + +# shellcheck disable=SC1091 +# SC1091: Not following: ... was not specified as input (see shellcheck -x). + +# Exit with error if commands exit with non-zero and if undefined variables are +# used. +set -eu + +# shellcheck disable=SC2034 +# SC2034: ... appears unused. Verify use (or export if used externally). +prefix="@prefix@" + +# Include utilities. Use installed version if available and +# use build version if it isn't. +if test -f "@datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh"; then + . "@datarootdir@/@PACKAGE_NAME@/scripts/admin-utils.sh" +else + . "@abs_top_builddir@/src/bin/admin/admin-utils.sh" +fi + +# First argument must be the expected schema version . +# Check if it's passed at all. +if [ "$#" -lt "1" ]; then + printf "Required at least one parameter: schema version number, e.g. 7.0\n" + exit 1 +fi +exp_version="$1" +shift + +# Remaining arguments are used as mysql command line arguments + +# If the existing schema doesn't match, the fail +VERSION=$(mysql_version "$@") +if [ "$VERSION" = "" ]; then + printf "Cannot wipe data, schema version could not be detected.\n" + exit 1 +fi + +if [ "$VERSION" != "$exp_version" ]; then + printf 'Cannot wipe data, wrong schema version. ' + printf 'Expected version %s, found %s.\n' "$exp_version" "$VERSION" + exit 1 +fi + +# Delete transient data from tables. Per MySQL documentation TRUNCATE +# destroys and there recreates tables. As schema updates are typically +# very slow, we're use deletes here. We turn off foreign key checks to +# worrying about table order. We also set the session variable +# disable_audit to turn off Back audit procedures, to avoid attempting +# to create entries for deleted records. +mysql "$@" <