google-cloud-firestoreschema-migration

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


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.


Solution

  • 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.