Exemple #1
0
 def setUpClass(cls):
     cls.conn = r.connect()
     try:
         r.db_drop('test').run(cls.conn)
     except errors.ReqlOpFailedError:
         pass
     r.db_create('test').run(cls.conn)
Exemple #2
0
def drop_db():
    '''
    Drops Database
    '''
    try:
        db_name = app.config['DATABASE_NAME']
        conn = r.connect()
        if db_name in r.db_list().run(conn):
            r.db_drop(db_name).run(conn)
    except Exception as e:
        cprint("An error occured --> {0}".format(e), 'red', attrs=['bold'])
Exemple #3
0
def real_stock_data_load(data, connection):
    for db in list(r.db_list().run(connection)):
        if db == "rethinkdb":
            # This db is special and can't be deleted.
            continue
        r.db_drop(db).run(connection)
    for db_name, db_data in iteritems(data['dbs']):
        r.db_create(db_name).run(connection)
        for table_name, table_data in iteritems(db_data['tables']):
            r.db(db_name).table_create(table_name).run(connection)
            r.db(db_name).table(table_name).insert(table_data).run(connection)
Exemple #4
0
def drop_db(database, connection):
    try:
        result = r.db_drop(database).run(connection)
        if result["dbs_dropped"] == 0:
            raise Exception(
                f"Drop Error.\n Couldn't drop database in:" f"\n\tDatabase: {database}"
            )
    except Exception as err:
        logging.error(
            f"[ERROR] Error trying to drop database at "
            f"db.py/drop_db.\nTraceback: {err}"
        )
        return {"dbs_dropped": 0, "tables_dropped": 0}
    else:
        dbs_dropped = result["dbs_dropped"]
        tables_dropped = result["tables_dropped"]
        logging.info(
            f"[INFO] Number of databases dropped: {dbs_dropped}."
            f"\n[INFO] Number of tables "
            f"dropped: {tables_dropped}.\nData: {result}"
        )
        return {"dbs_dropped": dbs_dropped, "tables_dropped": tables_dropped}
Exemple #5
0
 def test_db_drop(self, conn):
     expected = set(['db_one'])
     r.db_drop('db_two').run(conn)
     result = self.db_list(conn)
     assertEqual(expected, result)
Exemple #6
0
    def tearDown(self):
        super(DbBaseTestCase, self).tearDown()

        # Drop test database
        with get_conn() as conn:
            r.db_drop('testing').run(conn)
Exemple #7
0
 def tearDownClass(cls):
     r.db_drop('test').run(cls.conn)
     cls.conn.close()
Exemple #8
0
def drop_db(db_name):
    return r.db_drop(db_name)