我可以使用 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
这样,每当我的列族模式发生变化时,例如添加新列,表就会用新列更新,而不会删除表中的现有条目。