Registry / database / alter-firestore

alter-firestore

JSON →
library2.1.8jsnpmunverified

A CLI tool for managing Firestore schema migrations and data alterations using TypeScript files. v2.1.8 requires Node.js >=21.0.0 and is Pure ESM (package.json must have type:module). Supports migration up/down, rollback, refresh, and custom alter scripts. Runs against Firestore emulator or production projects via Firebase Admin SDK. Ships TypeScript definitions. The tool exports ActionArg types for migration/alter functions.

npm install alter-firestore
INSTALL
IMPORT
SIG · ALTER-FIRESTORE
A
alter-firestore
databasejavascriptv2.1.8
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ActionArg
✓ import { ActionArg } from 'alter-firestore/types/command'
✗ import { ActionArg } from 'alter-firestore'
ActionArg is not exported from the main entry; must use 'alter-firestore/types/command' subpath.
MigrateOptions
✓ import { MigrateOptions } from 'alter-firestore/types/options'
✗ import { MigrateOptions } from 'alter-firestore'
Options types are in the 'types/options' subpath.
require('alter-firestore')
✓ import ... from 'alter-firestore'
✗ const alter = require('alter-firestore')
This package is Pure ESM and cannot be used with CommonJS require(). Package.json must contain 'type': 'module'.

Setup and create a basic migration file that creates a document (up) and deletes it (down), then run against the Firestore emulator.

// Set package.json type to module // package.json: { "type": "module" } // Install // npm i alter-firestore // Install ts-node for TypeScript execution // npm i -D ts-node // Create .alfsrc.js export default { emulator: { options: { projectId: 'demo-project' }, ports: { firestore: '8080' }, }, credentialPaths: { staging: './staging-key.json' }, migrations: { collectionName: 'migrations', directoryPath: 'migrations' }, }; // Create a migration file: migrations/001_create_users.ts import { ActionArg } from 'alter-firestore/types/command'; import { MigrateOptions } from 'alter-firestore/types/options'; export const up = async ({ firestore }: ActionArg<MigrateOptions>) => { return firestore.create('users', 'user1', { name: 'Alice' }); }; export const down = async ({ firestore }: ActionArg<MigrateOptions>) => { const ref = firestore.doc('users/user1'); return firestore.recursiveDelete('users', ref); }; // Run migration against emulator // npm run alfs -- migrate // or: node --loader ts-node/esm node_modules/.bin/alfs migrate
Debug
Known issues
breakingNode.js version must be >=21.0.0 and >=22.0.0. Older versions will cause runtime errors.
fix
Update Node.js to 21.x or 22.x. Check with 'node --version'.
affects: <21.0.0
breakingPackage is Pure ESM and cannot be loaded with require(). CommonJS projects will fail with ERR_REQUIRE_ESM.
fix
Set 'type': 'module' in your package.json. Use import syntax instead of require().
affects: >=2.0.0
gotchaActionArg and options types must be imported from subpaths like 'alter-firestore/types/command', not from the main export.
fix
Use import { ActionArg } from 'alter-firestore/types/command'.
affects: >=2.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module
Package is Pure ESM but loaded with require() in a CommonJS context.
fix
Add 'type': 'module' to package.json or dynamically import().
TypeError: Cannot read properties of undefined (reading '…')
.alfsrc.js is missing or incorrectly configured, or a required credential path is not set.
fix
Ensure .alfsrc.js exists with proper fields for your environment (emulator or credentialPaths).
Upgrade
Version history
2.1.8latest on npm
Audit
Dependencies
firebase-adminrequiredUsed to interact with Firestore (getDoc, create, recursiveDelete)
ts-nodeoptionalRequired to execute TypeScript migration/alter files via ts-node-esm
Agent activity
37 hits · last 30 days
node
32
OpenAI (training)
1
Resources
alter-firestore — npm install alter-firestore · libregistry