/ upgrading / upgradeReplies.js
upgradeReplies.js
 1  // if you have an instance of Auride that runs old notes
 2  // before September 15, 2025 that hosts replies,
 3  // please run this script to upgrade your replies from our old form
 4  // (which is running through every /note/ entry looking for the replyingTo value)
 5  // to our new method!
 6  
 7  // run npm install to install dependencies for this script
 8  const admin = require("firebase-admin");
 9  const serviceAccount = require("./serviceAccountKey.json");
10  admin.initializeApp({
11      credential: admin.credential.cert(serviceAccount),
12      databaseURL: "https://chat-transsocial-test-default-rtdb.firebaseio.com"
13  });
14  
15  const db = admin.database();
16  
17  async function migrateReplies() {
18      try {
19          // get the notes, assuming there are any
20          const notesSnap = await db.ref("/notes").once("value");
21          if (!notesSnap.exists()) {
22              console.log("No notes exist.");
23              return;
24          }
25  
26          // then, migrate notes
27          const notes = notesSnap.val();
28          for (const noteId in notes) {
29              const note = notes[noteId];
30              if (note.replyingTo) {
31                  const parentId = note.replyingTo;
32                  const replyRef = db.ref(`/notes/${parentId}/notesReplying`).push();
33                  await replyRef.set({
34                      id: noteId,
35                      ...note
36                  });
37  
38                  // now remove the old entry
39                  await db.ref(`/notes/${noteId}`).remove();
40  
41                  console.log(`Moved note ${noteId} under replies of ${parentId}!`);
42              } else {
43                  console.log("Not a reply! Skipping.");
44              }
45          }
46  
47          console.log("Finished migrating replies!");
48      } catch (err) {
49          console.error("Error migration replies: ", err);
50      }
51  }
52  
53  migrateReplies();