From 1edb7399bcadb9f814bc62c2db78b2f222e7bbf4 Mon Sep 17 00:00:00 2001 From: Steven Murray <Steven.Murray@cern.ch> Date: Thu, 27 Apr 2017 17:46:30 +0200 Subject: [PATCH] cta/CTA#87 cta-catalogue-delete-all-data and cta-catalogue-schema-drop should require interactive confirmation Made the cta-catalogue-schema-drop command interactive --- catalogue/DropSchemaCmd.cpp | 25 ++++++++++++++++++- catalogue/DropSchemaCmd.hpp | 9 +++++++ .../buildtree_runner/cc7/opt/run/bin/init.sh | 2 +- .../ctafrontend/cc7/opt/run/bin/init.sh | 2 +- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/catalogue/DropSchemaCmd.cpp b/catalogue/DropSchemaCmd.cpp index c39a2c0a07..f4a7965351 100644 --- a/catalogue/DropSchemaCmd.cpp +++ b/catalogue/DropSchemaCmd.cpp @@ -83,11 +83,34 @@ int DropSchemaCmd::exceptionThrowingMain(const int argc, char *const *const argv } } - dropCatalogueSchema(dbLogin); + if(userConfirmsDropOfSchema(dbLogin)) { + m_out << "DROPPING the schema of the CTA calalogue database" << std::endl; + dropCatalogueSchema(dbLogin); + } else { + m_out << "Aborting" << std::endl; + } return 0; } +//------------------------------------------------------------------------------ +// userConfirmsDropOfSchema +//------------------------------------------------------------------------------ +bool DropSchemaCmd::userConfirmsDropOfSchema(const rdbms::Login &dbLogin) { + m_out << "WARNING" << std::endl; + m_out << "You are about to drop the schema of the CTA calalogue database" << std::endl; + m_out << " Database name: " << dbLogin.database << std::endl; + m_out << "Are you sure you want to continue?" << std::endl; + + std::string userResponse; + while(userResponse != "yes" && userResponse != "no") { + m_out << "Please type either \"yes\" or \"no\" > "; + std::getline(m_in, userResponse); + } + + return userResponse == "yes"; +} + //------------------------------------------------------------------------------ // dropCatalogueSchema //------------------------------------------------------------------------------ diff --git a/catalogue/DropSchemaCmd.hpp b/catalogue/DropSchemaCmd.hpp index 2d551baa76..1687aae2b1 100644 --- a/catalogue/DropSchemaCmd.hpp +++ b/catalogue/DropSchemaCmd.hpp @@ -64,6 +64,15 @@ private: */ void printUsage(std::ostream &os) override; + /** + * Asks the user to confirm that they want to drop the schema of the catalogue + * database. + * + * @param dbLogin The database login. + * @return True if the user confirmed. + */ + bool userConfirmsDropOfSchema(const rdbms::Login &dbLogin); + /** * Unconditionally drops the schema of the catalogue database associated with * the specified database login. diff --git a/continuousintegration/docker/buildtree_runner/cc7/opt/run/bin/init.sh b/continuousintegration/docker/buildtree_runner/cc7/opt/run/bin/init.sh index d78a075f44..c02ca69045 100755 --- a/continuousintegration/docker/buildtree_runner/cc7/opt/run/bin/init.sh +++ b/continuousintegration/docker/buildtree_runner/cc7/opt/run/bin/init.sh @@ -41,7 +41,7 @@ if [ "$KEEP_DATABASE" == "0" ]; then echo "Wiping database" cta-catalogue-schema-unlock /etc/cta/cta_catalogue_db.conf cta-catalogue-schema-status /etc/cta/cta_catalogue_db.conf - cta-catalogue-schema-drop /etc/cta/cta_catalogue_db.conf + echo yes | cta-catalogue-schema-drop /etc/cta/cta_catalogue_db.conf if [ "$DATABASETYPE" == "sqlite" ]; then mkdir -p $(dirname $(echo ${DATABASEURL} | cut -d: -f2)) diff --git a/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/init.sh b/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/init.sh index 29f0a6af93..f707f79d7b 100755 --- a/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/init.sh +++ b/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/init.sh @@ -49,7 +49,7 @@ if [ "$KEEP_DATABASE" == "0" ]; then echo "Wiping database" cta-catalogue-schema-unlock /etc/cta/cta_catalogue_db.conf cta-catalogue-schema-status /etc/cta/cta_catalogue_db.conf - cta-catalogue-schema-drop /etc/cta/cta_catalogue_db.conf + echo yes | cta-catalogue-schema-drop /etc/cta/cta_catalogue_db.conf if [ "$DATABASETYPE" == "sqlite" ]; then mkdir -p $(dirname $(echo ${DATABASEURL} | cut -d: -f2)) -- GitLab