CLI Configuration
Configure MSR Firebase CLI through flags, environment variables, and config files.
Table of contents
- Configuration Priority
- Firebase-Specific Flags
- Standard MSR Flags
- Environment Variables
- Config Files
- Complete Example
Configuration Priority
Configuration sources are applied in this order (highest to lowest priority):
- CLI Flags - Command-line arguments
- Environment Variables -
.envfile or shell exports - Config File -
msr.config.jsor via--config-file
Firebase-Specific Flags
–database-url
Firebase Realtime Database URL.
npx msr-firebase migrate --database-url https://your-project.firebaseio.com
Environment Variable:
export DATABASE_URL=https://your-project.firebaseio.com
Config File:
module.exports = {
databaseUrl: 'https://your-project.firebaseio.com'
};
–credentials
Path to Firebase service account key JSON file.
npx msr-firebase migrate --credentials ./serviceAccountKey.json
Environment Variable:
export GOOGLE_APPLICATION_CREDENTIALS=./serviceAccountKey.json
Config File:
module.exports = {
applicationCredentials: './serviceAccountKey.json'
};
–backup-mode
Control backup behavior during migrations.
npx msr-firebase migrate --backup-mode create_only
Values:
full- Create backup, restore on error, delete on success (default)create_only- Create backup but don’t restore automaticallyrestore_only- Don’t create backup, restore from existing on errormanual- No automatic backup/restore
Examples:
# No automatic backup (you manage backups manually)
npx msr-firebase migrate --backup-mode manual
# Create backup but use down() for rollback
npx msr-firebase migrate --backup-mode create_only
# Full automatic (default)
npx msr-firebase migrate --backup-mode full
Environment Variable:
export MSR_BACKUP_MODE=create_only
Standard MSR Flags
MSR Firebase inherits standard flags from MSR Core:
–folder
Migrations directory.
npx msr-firebase migrate --folder ./db/migrations
Default: ./migrations
Environment Variable: MSR_FOLDER
–table-name
Migration tracking table name.
npx msr-firebase migrate --table-name migration_history
Default: schema_version
Environment Variable: MSR_TABLE_NAME
–config-file
Load configuration from file.
npx msr-firebase migrate --config-file ./msr.config.prod.js
–dry-run
Simulate without executing changes.
npx msr-firebase migrate --dry-run
–no-lock
Disable migration locking.
npx msr-firebase migrate --no-lock
–format
Output format.
npx msr-firebase list --format json
Values: table, json
–logger
Logger type.
npx msr-firebase migrate --logger file --log-file ./migrations.log
Values: console, file, silent
–log-level
Logging verbosity.
npx msr-firebase migrate --log-level debug
Values: error, warn, info, debug
Environment Variables
Firebase-Specific
DATABASE_URL=https://your-project.firebaseio.com
GOOGLE_APPLICATION_CREDENTIALS=./serviceAccountKey.json
Standard MSR Variables
MSR_FOLDER=./migrations
MSR_TABLE_NAME=schema_version
MSR_BACKUP_MODE=full
MSR_LOG_LEVEL=info
For complete list of standard environment variables, see MSR Core Environment Variables.
Config Files
Basic Config
Create msr.config.js:
module.exports = {
databaseUrl: process.env.DATABASE_URL,
applicationCredentials: process.env.GOOGLE_APPLICATION_CREDENTIALS,
folder: './migrations',
tableName: 'schema_version'
};
Usage:
npx msr-firebase migrate --config-file ./msr.config.js
Environment-Specific Configs
Development:
// msr.config.dev.js
module.exports = {
databaseUrl: 'http://localhost:9000?ns=my-project-dev',
applicationCredentials: './dev-key.json',
shift: 'development'
};
Production:
// msr.config.prod.js
module.exports = {
databaseUrl: process.env.PROD_DATABASE_URL,
applicationCredentials: process.env.PROD_CREDENTIALS,
shift: 'production',
locking: {
enabled: true,
timeout: 600000
}
};
Usage:
# Development
npx msr-firebase migrate --config-file ./msr.config.dev.js
# Production
npx msr-firebase migrate --config-file ./msr.config.prod.js
Complete Example
Combining all configuration methods:
# .env file
DATABASE_URL=https://staging.firebaseio.com
MSR_FOLDER=./migrations
# Command with overrides
npx msr-firebase migrate \
--credentials ./staging-key.json \
--backup-mode create_only \
--log-level debug
Priority Resolution:
--credentials ./staging-key.json(CLI flag - highest)DATABASE_URLfrom.env(environment variable)MSR_FOLDERfrom.env(environment variable)- Other defaults from MSR Core