Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any concepts for firestore db schema migrations comparable to rails ActiveRecord migrations?

Tags:

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.

like image 574
Mutual Exception Avatar asked Nov 27 '18 02:11

Mutual Exception


People also ask

What is DB migrate in Rails?

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.

How do I use firestore in Swift?

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 .


2 Answers

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.

like image 143
kevlened Avatar answered Sep 19 '22 10:09

kevlened


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.

like image 37
Alex Mamo Avatar answered Sep 21 '22 10:09

Alex Mamo