quangkid
quangkid

Reputation: 1418

Cassandra Schema Migration for Java in Spring Boot

I use Cassandra Schema Migration library to initialize database whenever run project. By the tutorial :

Database database = new Database(cluster, "nameOfMyKeyspace");
MigrationTask migration = new MigrationTask(database, new MigrationRepository());
migration.migrate();

Where should I put above script to : in SpringBootApplication or Cassandra Config or something else?

How to keep and check the version of database? Is there any tutorial for this library?

Upvotes: 1

Views: 2634

Answers (1)

nonysingh
nonysingh

Reputation: 91

You can add a CommandLineRunner class which will run at start of application. Something like this :

@Component
@Slf4j
public class AppStartupRunner implements CommandLineRunner {

@Autowired
Cluster cluster;

@Autowired
private Environment environment;

@Override
public void run(String...args) throws Exception {
    log.info("Starting DB Migration");
    Database database = new Database(cluster, environment.getProperty("cassandra.keyspace"));
    MigrationTask migration = new MigrationTask(database, new MigrationRepository("resources/cassandra/migration"));
    migration.migrate();
    log.info("DB Migration Complete");
}

}

Hope this helps.

Upvotes: 3

Related Questions