Example #1
0
def drop_db(name=DB_NAME):
    if db_exist(name):
        database = backend.Database(name)
        database.close()
        Cache.purge_listeners(name)

        with Transaction().start(None, 0, close=True,
                                 autocommit=True) as transaction:
            Cache.drop(name)
            database.drop(transaction.connection, name)
            Pool.stop(name)
Example #2
0
def _pg_dump(cache_file):
    cmd = ['pg_dump', '-f', cache_file, '-F', 'c']
    options, env = _pg_options()
    cmd.extend(options)
    cmd.append(DB_NAME)
    try:
        return not subprocess.call(cmd, env=env)
    except OSError:
        cache_name, _ = os.path.splitext(os.path.basename(cache_file))
        cache_name = backend.TableHandler.convert_name(cache_name)
        # Ensure any connection is left open
        backend.Database(DB_NAME).close()
        with Transaction().start(None, 0, close=True,
                                 autocommit=True) as transaction:
            transaction.database.create(transaction.connection, cache_name,
                                        DB_NAME)
        open(cache_file, 'a').close()
        Cache.purge_listeners(DB_NAME)
        return True