CLI for syncing Firebase and handling migrations.
$ npm install @boundstate/firebase-migrate
Migrating data in Firebase production apps is hard.
The aim of this tool is to ease the process, avoiding data loss or disruptions to services.
Each version of data is prefixed (e.g.
/v2) so that apps can still function until they are updated.
Rules for each version are defined in separate files, and are automatically combined and updated so that only the latest
version of data is writable.
Configure your project by creating
firebase-migrate.json at the project root:
environment: map of projects to maps of Firebase functions config keys to ENV var names. (Config is set during the migration process before cloud functions are deployed)
migrations: path to migrations
databaseRules: path to Bolt files
Important: If using TypeScript, compile migrations before running the CLI, and point the
firebase-migrate.jsonto the build folder.
Create a migration
Create a migration file
Before this function is run, all data will be automatically copied from
/v2. Database operations performed in the function are automatically prefixed with
Create a file in your rules folder named
v2-rules.boltand define the security rules
Update references in your app code to use the
Using the CLI
Deploy to Firebase and apply any new migrations:
$ firebase-migrate --project <projectId>
Deploy only database rules, functions and/or storage rules (skipping migrations):
$ firebase-migrate --project <projectId> --only database functions storage
- Load database metadata - If db metadata indicates a deploy is already in progress, this process is cancelled (unless the CLI is run with
- Parse database rules - Compiles database Bolt rules.
- Parse migrations - Parses migration files and calculates a migration path if necessary.
- Prepare database - Sets database metadata to indicate that a deploy (and a migration) is in progress.
- Migrate - Makes the database read-only and runs any necessary migrations.
- Deploy database rules - Combines and deploys the database rules, with all previous versions made read-only.
- Deploy storage rules
- Set functions config
- Deploy functions - This is done last so that any db triggers are not run during the migration.