def create_index(model, index, keyspaces=None, connections=None):
    """
    Creates a new Search Index for the table indicated by the model,
    if it not exists.

    If `keyspaces` is specified, the index will be created for all
    specified keyspaces. Note that the `Model.__keyspace__` is
    ignored in that case.

    If `connections` is specified, the index will be synched for all
    specified connections. Note that the `Model.__connection__` is
    ignored in that case.
    If not specified, it will try to get the connection from the Model.


    **This function should be used with caution, especially in
    production environments.
    Take care to execute schema modifications in a single context
    (i.e. not concurrently with other clients).**

    *There are plans to guard schema-modifying functions with an
    environment-driven conditional.*
    """

    context = management._get_context(keyspaces, connections)
    for connection, keyspace in context:
        with query.ContextQuery(model, keyspace=keyspace) as m:
            _create_index(m, index, connection=connection)
Beispiel #2
0
def sync_table(model, keyspaces=None, connections=None):
    """
    Inspects the model and creates / updates the corresponding table and columns.

    If `keyspaces` is specified, the table will be synched for all specified keyspaces.
    Note that the `Model.__keyspace__` is ignored in that case.

    If `connections` is specified, the table will be synched for all specified connections. Note that the `Model.__connection__` is ignored in that case.
    If not specified, it will try to get the connection from the Model.

    Any User Defined Types used in the table are implicitly synchronized.

    This function can only add fields that are not part of the primary key.

    Note that the attributes removed from the model are not deleted on the database.
    They become effectively ignored by (will not show up on) the model.

    **This function should be used with caution, especially in production environments.
    Take care to execute schema modifications in a single context (i.e. not concurrently with other clients).**

    *There are plans to guard schema-modifying functions with an environment-driven conditional.*
    """

    context = _get_context(keyspaces, connections)
    for connection, keyspace in context:
        with query.ContextQuery(model, keyspace=keyspace) as m:
            _sync_table(m, connection=connection)