-
Notifications
You must be signed in to change notification settings - Fork 477
/
EndpointProfileMigration.java
43 lines (34 loc) · 1.34 KB
/
EndpointProfileMigration.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
38
39
40
41
42
43
package org.kaaproject.kaa.server.datamigration;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;
import static com.mongodb.client.model.Filters.eq;
public class EndpointProfileMigration {
private String host;
private String dbName;
private String nosql;
public EndpointProfileMigration(String host, String db, String nosql) {
dbName = db;
this.host = host;
this.nosql = nosql;
}
/**
* Add field use_raw_configuration_schema to endpointProfile that used to support devices using SDK version 0.9.0
* */
public void transform() {
//mongo
MongoClient client = new MongoClient(host);
MongoDatabase database = client.getDatabase(dbName);
MongoCollection<Document> endpointProfile = database.getCollection("endpoint_profile");
endpointProfile.updateMany(new Document(), eq("$set", eq("use_raw_schema", false)));
//cassandra
Cluster cluster = Cluster.builder().addContactPoint(host).build();
Session session = cluster.connect(dbName);
session.execute("ALTER TABLE ep_profile ADD use_raw_schema boolean");
session.close();
cluster.close();
}
}