def _update_options(model, connection=None):
    """Updates the table options for the given model if necessary.

    :param model: The model to update.
    :param connection: Name of the connection to use

    :return: `True`, if the options were modified in Cassandra,
        `False` otherwise.
    :rtype: bool
    """
    ks_name = model._get_keyspace()
    msg = format_log_context("Checking %s for option differences", keyspace=ks_name, connection=connection)
    log.debug(msg, model)
    model_options = model.__options__ or {}

    table_meta = _get_table_metadata(model, connection=connection)
    # go to CQL string first to normalize meta from different versions
    existing_option_strings = set(table_meta._make_option_strings(table_meta.options))
    existing_options = _options_map_from_strings(existing_option_strings)
    model_option_strings = metadata.TableMetadataV3._make_option_strings(model_options)
    model_options = _options_map_from_strings(model_option_strings)

    update_options = {}
    for name, value in model_options.items():
        try:
            existing_value = existing_options[name]
        except KeyError:
            msg = format_log_context("Invalid table option: '%s'; known options: %s", keyspace=ks_name, connection=connection)
            raise KeyError(msg % (name, existing_options.keys()))
        if isinstance(existing_value, six.string_types):
            if value != existing_value:
                update_options[name] = value
        else:
            try:
                for k, v in value.items():
                    if existing_value[k] != v:
                        update_options[name] = value
                        break
            except KeyError:
                update_options[name] = value

    if update_options:
        options = ' AND '.join(metadata.TableMetadataV3._make_option_strings(update_options))
        query = "ALTER TABLE {0} WITH {1}".format(model.column_family_name(), options)
        execute(query, connection=connection)
        return True

    return False
def _update_options ( model , connection = None ) : ks_name = model . _get_keyspace ( ) msg = format_log_context ( "Checking %s for option differences" , keyspace = ks_name , connection = connection ) log . debug ( msg , model ) model_options = model . __options__ or { } table_meta = _get_table_metadata ( model , connection = connection ) existing_option_strings = set ( table_meta . _make_option_strings ( table_meta . options ) ) existing_options = _options_map_from_strings ( existing_option_strings ) model_option_strings = metadata . TableMetadataV3 . _make_option_strings ( model_options ) model_options = _options_map_from_strings ( model_option_strings ) update_options = { } for name , value in model_options . items ( ) : try : existing_value = existing_options [ name ] except KeyError : msg = format_log_context ( "Invalid table option: '%s'; known options: %s" , keyspace = ks_name , connection = connection ) raise KeyError ( msg % ( name , existing_options . keys ( ) ) ) if isinstance ( existing_value , six . string_types ) : if value != existing_value : update_options [ name ] = value else : try : for k , v in value . items ( ) : if existing_value [ k ] != v : update_options [ name ] = value break except KeyError : update_options [ name ] = value if update_options : options = ' AND ' . join ( metadata . TableMetadataV3 . _make_option_strings ( update_options ) ) query = "ALTER TABLE {0} WITH {1}" . format ( model . column_family_name ( ) , options ) execute ( query , connection = connection ) return True return False
Updates the table options for the given model if necessary.

    :param model: The model to update.
    :param connection: Name of the connection to use

    :return: `True`, if the options were modified in Cassandra,
        `False` otherwise.
    :rtype: bool