Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 mongoDB migration #2

Open
cdupont opened this issue May 8, 2019 · 3 comments
Open

V2 mongoDB migration #2

cdupont opened this issue May 8, 2019 · 3 comments

Comments

@cdupont
Copy link
Contributor

cdupont commented May 8, 2019

Data from MongoDB and MySQL need to be migrated to new format.
Old format:

  • each domain as a collection
  • document format:
{ "_id" : ObjectId("5b5a022ef21f630001b4be6e"), "entityID" : "FL_Sensor32", "entityType" : "SensingDevice", "attributeID" : "SMC", "value" : "327.50", "timestamp" : ISODate("2018-07-26T17:17:30Z") }

New format:

  • one collection for all datapoints (called "waziup_history")
  • document format:
{ "_id" : ObjectId("5cd308bd41dabe0006000000"), "sensor_id" : "TC1", "device_id" : "MyDevice", "value" : 25, "timestamp" : "2016-06-08T18:20:27.873Z" }
@cdupont
Copy link
Contributor Author

cdupont commented May 8, 2019

Actions:

  • merge all documents in the same collection
  • rename entityID -> device_id
  • rename attributeID -> sensor_id
  • remove SensingDevice

@cdupont cdupont changed the title V2 databases migrations V2 mongDB migration May 8, 2019
@cdupont cdupont changed the title V2 mongDB migration V2 mongoDB migration May 8, 2019
@cdupont
Copy link
Contributor Author

cdupont commented May 14, 2019

Used this script:

use waziup_history;
db.getCollectionNames().forEach(function(collname) {
  db.getCollection(collname).copyTo(db.getSiblingDB('waziup')['waziup_history'])
  print(collname + " done");
});

use waziup;
db.waziup_history.update({}, {$rename:{"entityID":"device_id", "attributeID":"sensor_id"}, $unset: {"entityType":""}}, false, true);

@cdupont
Copy link
Contributor Author

cdupont commented May 15, 2019

Problem now is to add the keycloak Id for existing sensors. Or should they be considered public?
Script need to:

  • read a device
  • extract name
  • get resource in Keycloak with the same name
  • write the keycloak Id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant