-
Notifications
You must be signed in to change notification settings - Fork 21
/
InsertInitialItemsMigration.java
37 lines (28 loc) · 1.14 KB
/
InsertInitialItemsMigration.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;
import java.util.UUID;
public class InsertInitialItemsMigration extends DataMigration {
private final int count;
public InsertInitialItemsMigration(final int count, final int version) {
super(version);
this.count = count;
}
@Override
public String getDescription() {
return "Populate items by id table with initial data";
}
@Override
public void execute() throws MigrationException {
try {
final PreparedStatement preparedStatement =
session.prepare("INSERT INTO items_by_id (id, number, external_id) VALUES (?, ?, ?);");
for (int i = 0; i < count; i++) {
session.execute(preparedStatement.bind(UUID.randomUUID(), Integer.toString(i), UUID.randomUUID()));
}
} catch (final Exception e) {
throw new MigrationException("Failed to execute InsertInitialItemsMigration migration", e);
}
}
}