diff --git a/catalogue/DropSchemaCmd.cpp b/catalogue/DropSchemaCmd.cpp index c39a2c0a0766b81fdbb8e75852bcfe4c2177360f..f4a7965351f4798bb51f477f3998c07b427f6dc3 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 2d551baa76463367bb2bd5c164f51fd7d8138c54..1687aae2b1a959abf3c0da566e22de36fb3788ea 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 d78a075f44b791b28985760123996eac40e94fad..c02ca690451c2a2f265aa917fe7fcc3562c090e0 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 29f0a6af93c838ce410a509c4e1d05cecee41c3a..f707f79d7b6e78e499ed04d080d703199fa3059c 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))