How to Use Fireway: Your Schema Migration Tool for Firestore

Aug 22, 2023 | Programming

Welcome to the future of Firestore schema migration! Fireway is a powerful tool that streamlines the process of migrating your Firestore schema, borrowing inspiration from the well-known Flyway tool. In this article, we’ll explore how to install and use Fireway effectively, along with some troubleshooting tips to keep your migration process smooth and successful.

Installation

Setting up Fireway is simple. You can install it globally using either Yarn or NPX. Choose one of the following commands:

  • Using Yarn: yarn global add fireway
  • Using NPX: npx fireway

Setting Up Credentials

To connect Fireway to Firestore, you need to define the GOOGLE_APPLICATION_CREDENTIALS environment variable with the path to your service account file. Here’s how you can do this:

export GOOGLE_APPLICATION_CREDENTIALS=pathtofirestore-service-account.json

Using Fireway Command Line Interface (CLI)

The Fireway CLI is your gateway to migration commands. Here’s a basic command format:

$ fireway command [options]

Some of the available commands include:

  • migrate: Migrates schema to the latest version.
  • -v, –version: Displays the current version.
  • -h, –help: Displays help information.

Example Usage

  • To simply migrate: $ fireway migrate
  • To see help for migrate command: $ fireway migrate –help

Migrations: The Heart of Fireway

When you’re ready to migrate, the command will look something like this:

$ fireway migrate [options]

Each migration file follows a specific naming format: v[semver]__[description].js.

Explaining Migration Logic With an Analogy

Think of migration as a chef preparing a multi-course meal:

  • Gathering Ingredients: Just like the chef collects all necessary recipes (or migration files), Fireway collects all migration files sorted by version.
  • Checking Previous Dishes: The chef needs to know the last successfully completed dish (the last migration). If the previous dish failed, the chef must either fix it or start over.
  • Preparing the Meal: Only after confirming everything is in order does the chef begin cooking (running the migration scripts).

Typed Migrations

For developers who prefer type checking, Fireway supports two methods: TypeScript and JSDoc. To set up TypeScript, ensure you have ts-node installed and configure your tsconfig.json. Here’s a quick guide:

  1. Install ts-node.
  2. Set up the ts-node block in your tsconfig.json.
  3. Create your migration file in TypeScript.
  4. Run your migration using Fireway with the require option.

Running Local Tests

Before deploying migrations on actual Firestore, it’s prudent to test them locally. To connect to the Firestore emulator, define:

export FIRESTORE_EMULATOR_HOST=localhost:8080

This allows you to run migrations against your local emulator instance instead of the production database.

Migration Results

Once the migration process is complete, results are stored in a fireway collection, documenting successes and details about each migration performed.

Troubleshooting Tips

If you encounter any issues while using Fireway, consider the following:

  • Ensure that your environment variable GOOGLE_APPLICATION_CREDENTIALS is set correctly.
  • Check the naming format of your migration files to ensure they follow the required pattern.
  • Test your migrations locally with the Firestore emulator before deploying to production.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox