willhlaw / node-firestore-backup-restore

Google Firebase Firestore backup and restore tool
91 stars 24 forks source link

Add the ability to apply a transformation function to documents before backup or restoration #30

Closed pmarconi closed 1 year ago

pmarconi commented 6 years ago

Add a "schema migration" feature that add the ability to apply a transformation function before either writing to disk (so user can verify the schema migration) or before restoring to Firestore.

The proposal idea is to have a flag for this, called --transformFn or -T for the command line, where the user can indicate the path of a file from where the transformation function will be exported.

And for example will be executed like this:

firestore-backup-restore --accountCredentials cred.json --backupPath backups --transformFn transformFn.js

This transformation function should return a promise, and receive a object as parameter, which will contain the following fields:

accountDb {Object} Firestore database instance from where the backup is made restoreAccountDb {Object} Firestore database instance where the backup is restored collectionPath {Array} Array that contains the path of the collection docId {String} Id of the document, where the function will be applied docData {Object} Document data with "backup" format, specified below*

docData will have the format NAME: { "value": VALUE, "type": TYPE }, For example:

Task {
  "name": { "value": "Buy some apples", "type": "string" }
  "difficulty": { "value": "easy", "type": "string" },
}

The allowed types are: 'string', 'number', 'boolean', 'object', 'array', 'null', 'timestamp', 'geopoint', 'documentReference'

Example of transformation function:

export default transformFn;

willhlaw commented 6 years ago

@pmarconi, excellent idea and great work. I'm taking a look at the PR now.