23

Coming from a SQL background, I'm wondering how does one go about doing database migration in firebase?

Assume I have the following data in firebase {dateFrom: 2015-11-11, timeFrom: 09:00} .... and now the front-end client will store and expects data in the form {dateTimeFrom: 2015-011-11T09:00:00-07:00}. How do I update firebase such that all dateFrom: xxxx and timeFrom: yyyy are removed and replaced with dateTimeFrom: xxxxyyyy? Thanks.

3
  • 2
    Without seeing a snippet of your JSON (as text, not as a screenshot), knowing what programming language you're using and what you've already tried, this is way too underspecified. For a general introduction to common NoSQL data modeling patterns, see: highlyscalable.wordpress.com/2012/03/01/… Commented Feb 2, 2016 at 14:30
  • Thanks @FrankvanPuffelen for the feedback. In the context of my Grails experience, I'm familiar with their database migration plugin. Whenever, the db schema changed or columns were to be renamed, I could write a groovy script and the db migration plugin would execute the script and update the tables. Coming from that perspective, I'm exploring Polymer right now and was just wondering how to handle similar situations where keys are renamed or dropped etc. How should I go about it with firebase as my backend? I hope that made it a bit clearer. Commented Feb 3, 2016 at 2:05
  • Yeah, looking for a solution for this for iOS / Swift not sure the "Fireway" Node.js tool is viable for iOS (I see a pod for React but not to load node.js/yarn as a usable tool).
    – bias
    Commented Sep 5, 2022 at 18:16

4 Answers 4

8

I think you are looking for this: https://github.com/kevlened/fireway

I think is a bad idea to pollute a project with conditionals to update data on the fly.

It is a shame firestore doesn't implement a process for this as it is very common and required to keep the app and db in sync.

2
  • btw, this library does not implement a rollback mechanism, so we still need to build our own way to this. I think having perfect testing wouldn't be a solution, though! Commented Apr 13, 2022 at 13:45
  • Is there a similar tool for Swift / iOS?
    – bias
    Commented Sep 5, 2022 at 18:16
5

You have to create your own script that reads, transform and write it back. You may eider read one node at the time or read the whole DB if it is not big. You may decide to leave the logic to your client when it access to it (if it ever does)

1

FWIW, since I'm using Swift and there isn't a solution like Fireway (that I know of), I've submitted a feature request to the Firebase team that they've accepted as a potential feature.

Firebase DB migration feature

You can also submit a DB migration feature request to increase the likelihood that they create the feature.

0

1. Ensure You Have the Firebase Admin SDK for your_project Go to the Firebase Console. Select your your_project project. Navigate to Project settings > Service accounts. Click "Generate new private key" and save the JSON file securely. This file contains sensitive information that allows full access to your Firebase services.

npm install -g node-firestore-import-export

firestore-export --accountCredentials D:\path\filename.json --backupFile D:\path\backup.json --nodePath collection_name

firestore-import --accountCredentials D:\path\project-prod-firebase-adminsdk.json --backupFile D:\path\backup.json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.