Skip to content

Firestore Extension to automatically gather a history of changes to documents

License

Notifications You must be signed in to change notification settings

Nushio/historian

Repository files navigation

Historian

Description: Stores document changes in a subcollection, alongside a timestamp and a deleteAfter field, so that in combination with Firestore TTL, you can automatically delete these changes documents after a chosen period of time.

Details: Use this extension to automatically store changes to your firestore collections in a separate subcollection.

You can configure this extension with the subcollection name. The default subcollection is named historian.

You can configure this extension with the period of days the data will be stored. The default is 30 days. This requires configuration that this extension does not handle automatically: Setting the Firestore TTL to delete documents.

Standard Screenshot with Changes

Additional setup

After installing this extension and updating at least one document, so that the extension triggers and creates your historian subcollection, head to Google's Cloud Console and configure your Time-to-live (TTL) Policy.

Enter the collection group name of the subcollection, and the deleteAfter field as the timestamp field.

Data is typically deleted within 72 hours after its expiration date.

Billing

To install an extension, your project must be on the Blaze (pay as you go) plan

  • This extension uses other Firebase and Google Cloud Platform services, which have associated charges if you exceed the service’s no-cost tier:
    • Cloud Firestore
    • Cloud Functions (Node.js 16+ runtime. See FAQs)

Configuration Parameters:

  • Your Collection Name: Which collection will be monitored for changes.

  • Your SubCollection Name: The name of the subcollection where changes will be stored.

  • Your TTL Period: How many days should the data be stored for? This requires configuration that this extension does not handle automatically: Setting the Firestore TTL to delete documents.

  • Excluded Keys: Document fields that should be ignored when storing changes. This is useful for fields that are updated frequently, but do not need to be stored in the changelog. For example, a field that stores the last time the document was updated.

Cloud Functions:

  • processEvent: Listens for changes to the collection specified, and writes the changelog accordingly.

Access Required:

This extension will operate with the following project IAM roles:

  • datastore.user (Reason: Allows the extension to delete (user) data from Cloud Firestore.)

About

Firestore Extension to automatically gather a history of changes to documents

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published