我可以使用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
这样,只要我的列族的模式发生了变化,就像添加了一个新列一样,该表将使用新列更新,而不会删除表中的现有条目。
答案 0 :(得分: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;
}
如您所见,您要求的功能仍未实施。如果你认为这很重要,也许你可以将它贡献给项目。