Our firestore DB based model evolves naturally. Now we would like to update all existing documents to the new (implicit) schema.
Are there any tools supporting that or what are the best practices. I would love to have a concept comparable to the rails ActiveRecord migrations.
A Rails migration is a tool for changing an application's database schema. Instead of managing SQL scripts, you define database changes in a domain-specific language (DSL). The code is database-independent, so you can easily move your app to a new platform.
Setting up the Swift projectOpen the Xcode application and select App to scaffold a new project. Name the application, click the Next button, and choose where to save your application on your local machine. pod init initializes the pods while open Podfile opens a config terminal to update the Podfile .
I couldn't find a firestore schema migration tool, so I wrote fireway. It's currently very simple (it doesn't support reversing a migration), but it's been enough for my use case.
Here's an example migration script:
// migrations/v0.0.1__example.js module.exports.migrate = async ({firestore}) => { await firestore.collection('name').add({key: 'value'}); };
Then run fireway migrate
to migrate your default project.
Currently, for Firestore, you will have to write your own code to update all existing documents to the new (implicit) schema. I read a few weeks ago in a post, that Firestore team is working on making this easier in the future.
If your new schema require some changes in your entire database, you can also consider using Firestore import / export system, that allows you to dump your data into a GCS bucket. It is not in a JSON format as you probably expected but it is in a similar format as Cloud Datastore uses, so I think will help you solve this problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With