• Stars
    star
    277
  • Rank 148,875 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A schema migration tool for firestore

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="ts-node/register" 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="ts-node/register" 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. Ensure ts-node is installed

  2. Define a ts-node configuration block inside your tsconfig.json file:

    {
      "ts-node": {
        "transpileOnly": true,
        "compilerOptions": {
          "module": "commonjs"
        }
      }
    }
  3. 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'});
     };
  4. Run fireway migrate with the require option

    $ fireway migrate --require="ts-node/register"

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

More Repositories

1

pytest-parallel

A pytest plugin for parallel and concurrent testing
Python
313
star
2

isomorphic-webcrypto

🎲 webcrypto library for Node, React Native and IE11+
JavaScript
116
star
3

sikuli_cpython

UNMAINTAINED: A CPython wrapper around the sikuli standalone jar
Python
61
star
4

msrCrypto

GitHub mirror of the MSR JavaScript Cryptography Library
JavaScript
24
star
5

csvToXspf

Python
10
star
6

pyrson

A Digital Life Assistant (DLA) linking several Python libraries
Rust
10
star
7

debug-webpack-plugin

Debug webpack builds and plugins
JavaScript
9
star
8

Sahi

Sahi Open Source
Java
8
star
9

remarkable-node

Unofficial reMarkable api wrapper for node.js
JavaScript
6
star
10

pytanium

Wrapper for Selenium
Python
5
star
11

foodmarklet

Bookmarklet version of plainoldrecipe
JavaScript
5
star
12

hex-lite

📐 isomorphic hex library in 256 bytes
JavaScript
4
star
13

threadwork

Simple, no frills, threading in Node.js
JavaScript
4
star
14

b64-lite

🎮 isomorphic base64 library in 377 bytes
JavaScript
4
star
15

talkjs-node

A Node.js wrapper for the talkjs rest api
TypeScript
3
star
16

webcrypto-test-suite

A library to ensure your WebCrypto polyfill or shim works correctly
JavaScript
2
star
17

jose

🌐 Collection of JSON Web libraries
JavaScript
2
star
18

globally.js

Add javascript global event listeners in bulk
JavaScript
1
star
19

webcrypto-react-native-examples

Examples of using isomorphic-webcrypto with React Native
Objective-C
1
star
20

python-webdriver-stress-test

Stress test the Python Selenium WebDriver http://selenium-python.readthedocs.io/api.html
Python
1
star
21

Urika

Dead project
Java
1
star
22

swree

Bundles swr, htm, preact and wouter to skip the build step
JavaScript
1
star
23

ZK

(Z)illion (K)eys - Public app/license management.
Python
1
star