npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

fs-migrator

v1.0.7

Published

A CLI tool to assist with Firestore schema migrations

Downloads

3

Readme

fs-migrator.js

fs-migrator is a Node CLI tool for dealing with schema migrations for Google Cloud Firestore. It has a similar feel to Sequelize for SQL but applies required schema changes across all documents.

Very helpful if needing to make standardised changes to documents across multiple development environments.

Requirements

You will need to install the google-cloud SDK found here before using this tool.

How to install

npm install -g fs-migrator

Writing a migration file

module.exports = {
  /**
   * This will perform the migration to the database.
   * @param db
   * @param Firestore - Firestore library that contains useful classes like FieldValue, FieldPath & Timestamp
   * @returns {Promise<void>}
   */
  up: async (db, Firestore) => {
    let exampleCollection = await db.collection('example-collection').get()
    let documents = exampleCollection.docs

    // Run all your updates in a transaction
    await db.runTransaction(async (t) => {
      let transactionData = []
      // Extract all the data from the documents
      // All fetch requests must be done before any updates
      for(let doc of documents) {
        let docRef = doc.ref
        const d = await t.get(docRef);
        transactionData.push({id: doc.id, ref: docRef, data: d.data()})
      }
      // Apply updates to each document
      for(let {id, ref, data} of transactionData) {
        // Apply update to each document
        t.update(ref, {testValue: data.testValue + 1})
      }
      return
    });
  },
  /**
   * This will undo the migration applied in the `up` function.
   * @param db
   * @param Firestore - Firestore library that contains useful classes like FieldValue, FieldPath & Timestamp
   * @returns {Promise<void>}
   */
  down: async (db, Firestore) => {
    let exampleCollection = await db.collection('example-collection').get()
    let documents = exampleCollection.docs
    
    // Run all your updates in a transaction
    await db.runTransaction(async (t) => {
      let transactionData = []
      // Extract all the data from the documents
      // All fetch requests must be done before any updates
      for(let doc of documents) {
        let docRef = doc.ref
        const d = await t.get(docRef);
        transactionData.push({id: doc.id, ref: docRef, data: d.data()})
      }
      // Apply updates to each document
      for(let {id, ref, data} of transactionData) {
        // Undo changes
        t.update(ref, {testValue: data.testValue - 1})
      }
      return
    });
  }
}

Usage

Usage documentation

fs-migrator --help

Initialising directory for fs-migrator usage

fs-migrator init

Creating migration file

fs-migrator create --type migration --name migration_name --collection firestore-collection-name
fs-migrator create -t migration -n migration_name --collection firestore-collection-name

Applying migration

# Standard usage
fs-migrator migrate
# Specifying project and credentials
fs-migrator migrate --project gcp_project_name --credentials /path/to/credentials.json

Rolling back migration

fs-migrator migrate --rollback

Features coming soon...

  • [x] Provide CLI command for initialising directory
  • [x] Provide CLI command for creating migration file directory
  • [x] Provide CLI command for applying all migrations
  • [x] Provide CLI command for rolling back all migrations
  • [x] Create migration file from template
  • [ ] Migrate and rollback single files
  • [ ] Implement better logging include logging levels such as verbose, debug etc

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

MIT