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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@keii2k/fireway

v2.0.1

Published

Schema migration tool for Firestore

Downloads

3

Readme

COMMENT

this repo forked from fireway

changed typescript run with ts-node -> tsx

fireway

A schema migration tool for firestore heavily inspired by flyway

Install

yarn global add fireway

# or 

npx fireway

Credentials

In order to fireway be able to connect to firestore you need to set up the environment variable GOOGLE_APPLICATION_CREDENTIALS with service account file path.

Example:

export GOOGLE_APPLICATION_CREDENTIALS="path/to/firestore-service-account.json"

CLI

Usage
  $ fireway <command> [options]

Available Commands
  migrate    Migrates schema to the latest version

For more info, run any command with the `--help` flag
  $ fireway migrate --help

Options
  --require        Requires a module before executing
  -v, --version    Displays current version
  -h, --help       Displays this message

Examples
  $ fireway migrate
  $ fireway --require="require-tsx" migrate

fireway migrate

Description
  Migrates schema to the latest version

Usage
  $ fireway migrate [options]

Options
  --path         Path to migration files  (default ./migrations)
  --projectId    Target firebase project
  --dryrun       Simulates changes
  --forceWait    Forces waiting for migrations that do not strictly manage async calls
  --require      Requires a module before executing
  -h, --help     Displays this message

Examples
  $ fireway migrate
  $ fireway migrate --path=./my-migrations
  $ fireway migrate --projectId=my-staging-id
  $ fireway migrate --dryrun
  $ fireway migrate --forceWait
  $ fireway --require="require-tsx" migrate

Migration file format

Migration file name format: v[semver]__[description].js

// each script gets a pre-configured firestore admin instance
// possible params: app, firestore, FieldValue, FieldPath, Timestamp, dryrun
module.exports.migrate = async ({firestore, FieldValue}) => {
    await firestore.collection('name').add({key: FieldValue.serverTimestamp()});
};

Typed Migrations

For type checking and Intellisense, there are two options:

TypeScript

  1. Create a migration

     // ./migrations/v0.0.1__typescript-example.ts
    
     import { MigrateOptions } from 'fireway';
    
     export async function migrate({firestore} : MigrateOptions) {
         await firestore.collection('data').doc('one').set({key: 'value'});
     };
  2. Run fireway migrate with the require option

    $ fireway migrate --require="require-tsx"

JSDoc

Alternatively, you can use JSDoc for Intellisense

/** @param { import('fireway').MigrateOptions } */
module.exports.migrate = async ({firestore}) => {
    // Intellisense is enabled
};

Running locally

Typically, fireway expects a --projectId option that lets you specify the Firebase project associated with your Firestore instance against which it performs migrations. However, most likely you'll want to test your migration scripts locally first before running them against your actual (presumably, production) instances. If you are using the Firestore emulator, define the FIRESTORE_EMULATOR_HOST environment variable, e.g.:

export FIRESTORE_EMULATOR_HOST="localhost:8080"

The firestore node library will connect to your local instance. This way, you don't need a project ID and migrations will be run against your emulator instance. This works since fireway is built on the firestore node library.

Migration logic

  1. Gather all the migration files and sort them according to semver
  2. Find the last migration in the fireway collection
  3. If the last migration failed, stop. (remove the failed migration result or restore the db to continue)
  4. Run the migration scripts since the last migration

Migration results

Migration results are stored in the fireway collection in firestore

// /fireway/3-0.0.1-example

{
  checksum: 'fdfe6a55a7c97a4346cb59871b4ce97c',
  description: 'example',
  execution_time: 1221,
  installed_by: 'system_user_name',
  installed_on: firestore.Timestamp(),
  installed_rank: 3,
  script: 'v0.0.1__example.js',
  success: true,
  type: 'js',
  version: '0.0.1'
}

Contributing

# To install packages and firestore emulator
$ yarn
$ yarn setup

# To run tests
$ yarn test

License

MIT