1

我可以使用 Spring 数据 cassandra 创建表,其配置文件通过覆盖函数扩展 AbstractCassandraConfiguration

@Override
public SchemaAction getSchemaAction() {
    return SchemaAction.RECREATE_DROP_UNUSED;
}

@Override
public String[] getEntityBasePackages() {
    return new String[] {"com.example"}; //com.example package contains the bean with @table annotation
}

但它通过首先删除键空间中的所有表然后创建表来创建表。在此过程中,我丢失了表中的现有数据。我想实现类似 SchemaSync:https ://github.com/valchkou/cassandra-driver-mapping/blob/master/src/main/java/com/datastax/driver/mapping/schemasync/SchemaSync.java

这样,每当我的列族模式发生变化时,例如添加新列,表就会用新列更新,而不会删除表中的现有条目。

4

1 回答 1

1

这是包含可用选项的SchemaAction枚举的当前状态:

public enum SchemaAction {

    /**
     * Take no schema actions.
     */
    NONE,

    /**
     * Create each table as necessary. Fail if a table already exists.
     */
    CREATE,

    /**
     * Create each table as necessary, dropping the table first if it exists.
     */
    RECREATE,

    /**
     * Drop <em>all</em> tables in the keyspace, then create each table as necessary.
     */
    RECREATE_DROP_UNUSED;

    // TODO:
    // /**
    // * Validate that each required table and column exists. Fail if any required table or column does not exists.
    // */
    // VALIDATE,
    //
    // /**
    // * Alter or create each table and column as necessary, leaving unused tables and columns untouched.
    // */
    // UPDATE,
    //
    // /**
    // * Alter or create each table and column as necessary, removing unused tables and columns.
    // */
    // UPDATE_DROP_UNUNSED;
}

如您所见,您要求的功能仍未实现。如果你觉得它很重要,也许你可以将它贡献给项目。

于 2015-10-20T18:41:39.350 回答