forked from smartcat-labs/cassandra-migration-tool-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InsertBooksMigration.java
37 lines (29 loc) · 1.35 KB
/
InsertBooksMigration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package io.smartcat.migration.migrations.data;
import com.datastax.driver.core.PreparedStatement;
import io.smartcat.migration.DataMigration;
import io.smartcat.migration.exceptions.MigrationException;
/**
* Example of data migration used for populating data in table. This shows use case when you need to populate data in
* table fast. Can be used for test data, logic can be added to add near production like data in huge amounts.
*/
public class InsertBooksMigration extends DataMigration {
public InsertBooksMigration(final int version) {
super(version);
}
@Override
public String getDescription() {
return "Insert few books so we can show schema and data migration";
}
@Override
public void execute() throws MigrationException {
try {
final PreparedStatement preparedStatement =
session.prepare("INSERT INTO books (name, author) VALUES (?, ? );");
session.execute(preparedStatement.bind("Journey to the Center of the Earth", "Jules Verne"));
session.execute(preparedStatement.bind("Fifty Shades of Grey", "E. L. James"));
session.execute(preparedStatement.bind("Clean Code", "Robert C. Martin"));
} catch (final Exception e) {
throw new MigrationException("Failed to execute InsertBooksMigration migration", e);
}
}
}