Firebase Database Migration
Asked Answered
S

4

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.

Struma answered 2/2, 2016 at 7:51 Comment(3)
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/…Albinus
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.Struma
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).Benjie
D
7

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.

Donothingism answered 13/4, 2022 at 13:43 Comment(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!Donothingism
Is there a similar tool for Swift / iOS?Benjie
S
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)

Secretarial answered 18/3, 2017 at 12:52 Comment(0)
B
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.

Benjie answered 6/9, 2022 at 17:46 Comment(0)
T
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

Tevet answered 23/3, 2024 at 7:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.