def preprocess_data(config, force=False):
    """
    Ensures that all the necessary data have been inserted in db from the raw
    opendata files.

    :params config: A config dictionary.
    :params force: Whether to force rebuild or not.
    :return bool: Whether data have been built or not.
    """
    # Check if a build is required
    get_session = database.init_db(config["database"], config["search_index"])
    with get_session() as session:
        is_built = session.query(PublicTransport).count() > 0 and session.query(PostalCode).count() > 0
        if is_built and not force:
            # No need to rebuild the database, skip
            return False
        # Otherwise, purge all existing data
        session.query(PublicTransport).delete()
        session.query(PostalCode).delete()

    # Build all opendata files
    LOGGER.info("Rebuilding data...")
    for preprocess in data_files.PREPROCESSING_FUNCTIONS:
        data_objects = preprocess()
        if not data_objects:
            raise flatisfy.exceptions.DataBuildError("Error with %s." % preprocess.__name__)
        with get_session() as session:
            session.add_all(data_objects)
    LOGGER.info("Done building data!")
    return True