Commit 969e5194 authored by Steven Murray's avatar Steven Murray
Browse files

cta/CTA#87 cta-catalogue-delete-all-data and cta-catalogue-schema-drop should...

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
parent 28df04db
......@@ -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
//------------------------------------------------------------------------------
......
......@@ -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.
......
......@@ -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))
......
......@@ -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))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment