Last active
September 11, 2017 09:30
-
-
Save jessejohnson/50ab08841850e2c2a578eac53bb8ad2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void fixFbDb(){ | |
DatabaseReference entireDb = FirebaseDatabase.getInstance().getReference(); | |
final DatabaseReference goodRef = FirebaseDatabase.getInstance().getReference("vanilla-messages-debug"); | |
entireDb.addListenerForSingleValueEvent(new ValueEventListener() { | |
@Override | |
public void onDataChange(DataSnapshot dataSnapshot) { | |
for(DataSnapshot snapshot: dataSnapshot.getChildren()){ | |
if(snapshot.getKey().startsWith("vanilla-messages-debug-")){ | |
String badMessageId = snapshot.getKey().split("vanilla-messages-debug-")[1]; | |
LogUtils.d("FBDB - to migrate", badMessageId); | |
//if(badMessageId.equalsIgnoreCase("125-13043")){ | |
//List<Map<String, Object>> list = new ArrayList<>(); | |
for(DataSnapshot s: snapshot.getChildren()){ | |
LogUtils.d("FBDB - snap", s.getValue().toString()); | |
//Map<String, Object> map = new HashMap<>(); | |
//map.put(s.getKey(), s.getValue()); | |
//list.add(map); | |
//LogUtils.d("FBDB", "Map is " + map.toString()); | |
goodRef.child(badMessageId).child(s.getKey()).setValue(s.getValue()); | |
} | |
//} | |
} | |
} | |
} | |
@Override | |
public void onCancelled(DatabaseError databaseError) { | |
} | |
}); | |
goodRef.addListenerForSingleValueEvent(new ValueEventListener() { | |
@Override | |
public void onDataChange(DataSnapshot dataSnapshot) { | |
for(DataSnapshot snapshot: dataSnapshot.getChildren()){ | |
//LogUtils.d("FBDB - good", snapshot.getKey()); | |
} | |
} | |
@Override | |
public void onCancelled(DatabaseError databaseError) { | |
} | |
}); | |
// DatabaseReference sRef = FirebaseDatabase.getInstance().getReference("vanilla-messages-125-13043"); | |
// sRef.addChildEventListener(new ChildEventListener() { | |
// @Override | |
// public void onChildAdded(DataSnapshot dataSnapshot, String s) { | |
// LogUtils.d("FBDB", "got " + dataSnapshot.toString()); | |
// //FirebaseDatabase.getInstance().getReference("vanilla-messages/randomchildref").setValue(dataSnapshot); | |
// Map<String, Object> map = new HashMap<>(); | |
// map.put(dataSnapshot.getKey(), dataSnapshot.getValue()); | |
// LogUtils.d("FBDB", "Map is " + map.toString()); | |
// goodRef.child("randomchild2"); | |
// } | |
// | |
// @Override | |
// public void onChildChanged(DataSnapshot dataSnapshot, String s) { | |
// | |
// } | |
// | |
// @Override | |
// public void onChildRemoved(DataSnapshot dataSnapshot) { | |
// | |
// } | |
// | |
// @Override | |
// public void onChildMoved(DataSnapshot dataSnapshot, String s) { | |
// | |
// } | |
// | |
// @Override | |
// public void onCancelled(DatabaseError databaseError) { | |
// | |
// } | |
// }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void migrateDb(){ | |
final DatabaseReference sourceRef = FirebaseDatabase.getInstance().getReference("vanilla-messages-debug"); | |
final DatabaseReference destinationRef = FirebaseDatabase.getInstance().getReference("vanilla-debug/messages"); | |
sourceRef.addListenerForSingleValueEvent(new ValueEventListener() { | |
@Override | |
public void onDataChange(DataSnapshot dataSnapshot) { | |
LogUtils.d("FBDB dataSnapshot", dataSnapshot.getKey()); | |
for(DataSnapshot snapshot: dataSnapshot.getChildren()){ | |
LogUtils.d("FBDB children of ", snapshot.getKey()); | |
for(DataSnapshot snapChild: snapshot.getChildren()){ | |
LogUtils.d("FBDB", snapChild.getKey()); | |
destinationRef.child(snapshot.getKey()).push().setValue(snapChild.getValue()); | |
} | |
//add complementary link to find new app | |
long now = System.currentTimeMillis(); | |
ForumMessage updateMessage = new ForumMessage("Your messages will soon be unavailable! \n " + | |
"Please update your app to continue messaging https://goo.gl/P9qRT0", "Asoriba", "0", now); | |
sourceRef.child(snapshot.getKey()).child(String.valueOf(now)).setValue(updateMessage.toString()); | |
} | |
} | |
@Override | |
public void onCancelled(DatabaseError databaseError) { | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment