2017-08-11 81 views
0

我創建了一個Spring Boot微服務,它在數據流上運行聚合並將其寫入各種Cassandra表。我正在尋找一個類似於Flyway的Java庫,它將在資源文件夾中存在腳本的情況下遷移Cassandra模式。有沒有人有任何建議,最好是你個人用於製作的圖書館?Java中的Cassandra遷移庫

+0

也許你可以嘗試[liquibase擴展](https://github.com/liquibase/liquibase-cassandra) – bilak

+0

也許[支柱](https://github.com/comeara/pillar) – bilak

回答

0

我以前builtamont:在代碼

<dependency> 
     <groupId>com.builtamont</groupId> 
     <artifactId>cassandra-migration</artifactId> 
     <version>0.9</version> 
    </dependency> 

遷移:

import com.builtamont.cassandra.migration.CassandraMigration; 
import com.builtamont.cassandra.migration.api.configuration.KeyspaceConfiguration; 
import org.springframework.beans.factory.InitializingBean; 

class CassandraDataSourceMigration implements InitializingBean { 
    private final String ip; 
    private final String clusterName; 
    private final Integer port; 
    private final String keyspaceName; 
    private final String migrationsPath; 

    public CassandraDataSourceMigration(String ip, String clusterName, Integer port, String keyspaceName, String migrationsPath) { 
     this.ip = ip; 
     this.clusterName = clusterName; 
     this.port = port; 
     this.keyspaceName = keyspaceName; 
     this.migrationsPath = migrationsPath; 
    } 

    // getters/setters 

    @Override 
    public void afterPropertiesSet() throws Exception { 

     final KeyspaceConfiguration keyspaceConfig = new KeyspaceConfiguration(); 
     keyspaceConfig.setName(keyspaceName); 
     keyspaceConfig.getClusterConfig().setContactpoints(new String[]{ip}); 
     if (port != null) { 
      keyspaceConfig.getClusterConfig().setPort(port); 
     } 

     final CassandraMigration migrationProcessor = new CassandraMigration(); 
     migrationProcessor.setLocations(new String[]{migrationsPath}); 
     migrationProcessor.setKeyspaceConfig(keyspaceConfig); 
     migrationProcessor.migrate(); 
    } 
} 

application.properties

cassandra.ip=127.0.0.1 
cassandra.cluster=My cluster 
cassandra.keyspace=saya 
cassandra.migration=classpath:db/migration 
cassandra.port=9042 

而遷移腳本是在資源/ DB /遷移V1_0__Init_table.cql