def destroy_database(name): control = monetdb.control.Control(MONETDB_HOST, MONETDB_PORT, MONETDB_PASSPHRASE) try: control.stop(name) except monetdb.exceptions.OperationalError: pass control.destroy(name)
def recreate(dbconfig): """ Destroys and creates a new database. :param options: a argparse namespace generated with tkp.management WARNING: this will DESTROY your database! Note: this will raise an Exception ONLY when the creation of the database fails """ params = {'username': dbconfig['user'], 'password': dbconfig['password'], 'database': dbconfig['database'], 'host': dbconfig['host'] } if dbconfig['engine'] == 'monetdb': import monetdb.sql import monetdb.control control = monetdb.control.Control(dbconfig['host'], dbconfig['port'], dbconfig['passphrase']) database = dbconfig['database'] print("stopping %s" % database) try: control.stop(database) except monetdb.sql.OperationalError, e: print("database not running") print "destroying %s" % database try: control.destroy(database) except monetdb.sql.OperationalError, e: print("can't destroy database: %s" % str(e))