Configure Revisions Operation


  • Use ConfigureRevisionsOperation to apply the following revisions configuration to the database:

    • Default configuration - applies to all document collections.
    • Collection-specific configurations - override the default settings for these collections.
    • To apply a configuration for conflict document revisions see configure conflict revisions.
  • The configuration passed to this operation will REPLACE the current revisions configuration in the database.
    To MODIFY existing configuration, fetch the current configuration from the database record first.

  • After applying the configuration,
    revisions are created and purged for a document whenever the document is created, modified, or deleted.

  • To create a revision when there is no configuration defined (or enabled) see: force revision creation

  • By default, the operation will be applied to the default database.
    To operate on a different database see switch operations to different database.

  • In this page:


Replace configuration

In this example, we create a new RevisionsConfiguration for the database.
If revisions configuration already exists in the database - it will be replaced.

# ==============================================================================
# Define default settings that will apply to ALL collections
# Note: this is optional
default_rev_config = RevisionsCollectionConfiguration(
    minimum_revisions_to_keep=100,
    minimum_revisions_age_to_keep=timedelta(days=7),
    maximum_revisions_to_delete_upon_document_creation=15,
    purge_on_delete=False,
    disabled=False,
    # With this configuration:
    # ------------------------
    # * A revision will be created anytime a document is modified or deleted.
    # * Revisions of a deleted document can be accessed in the Revisions Bin view.
    # * At least 100 of the latest revisions will be kept.
    # * Older revisions will be removed if they exceed 7 days on next revision creation.
    # * A maximum of 15 revisions will be deleted each time a document is updated,
    #   until the defined '# of revisions to keep' limit is reached.
)

employees_rev_config = RevisionsCollectionConfiguration(
    minimum_revisions_to_keep=50,
    minimum_revisions_age_to_keep=timedelta(hours=12),
    purge_on_delete=True,
    disabled=False,
    # With this configuration:
    # ------------------------
    # * A revision will be created anytime an Employee document is modified.
    # * When a document is deleted all its revisions will be removed.
    # * At least 50 of the latest revisions will be kept.
    # * Older revisions will be removed if they exceed 12 hours on next revision creation.
)

# ==============================================================================
# Define a specific configuration for the EMPLOYEES collection
# This will override the default settings
products_rev_config = RevisionsCollectionConfiguration(
    disabled=True
    # No revisions will be created for the Products collection,
    # even though default configuration is enabled
)

# ==============================================================================
# Combine all configurations in the RevisionsConfiguration object
revisions_config = RevisionsConfiguration(
    default_config=default_rev_config,
    collections={"Employees": employees_rev_config, "Products": products_rev_config},
)

# ==============================================================================
# Define the configure revisions operation, pass the configuration
configure_revisions_op = ConfigureRevisionsOperation(revisions_config)

# Execute the operation by passing it to Maintenance.Send
# Any existing configuration will be replaced with the new configuration passed
store.maintenance.send(configure_revisions_op)

Modify configuration

In this example, we fetch the existing revisions configuration from the database record and modify it.

# ==============================================================================
# Define the get database record operation:
get_database_record_op = GetDatabaseRecordOperation(store.database)
# Get the current revisions configuration from the database record:
revisions_config = store.maintenance.server.send(get_database_record_op).revisions

# ==============================================================================
# If no revisions configuration exists, then create a new configuration
if revisions_config is None:
    revisions_config = RevisionsConfiguration(
        default_config=default_rev_config,
        collections={"Employees": employees_rev_config, "Products": products_rev_config},
    )

# ==============================================================================
# If a revisions configuration already exists, then modify it
else:
    revisions_config.default_config = default_rev_config
    revisions_config.collections["Employees"] = employees_rev_config
    revisions_config.collections["Products"] = products_rev_config

# ==============================================================================
# Define the configure revisions operation, pass the configuration
configure_revisions_op = ConfigureRevisionsOperation(revisions_config)

# Execute the operation by passing it to maintenance.send
# The existing configuration will be updated
store.maintenance.send(configure_revisions_op)

# Execute the operation by passing it to maintenance.send
# The existing configuration will be updated
store.maintenance.send(configure_revisions_op)

Syntax

class ConfigureRevisionsOperation(MaintenanceOperation[ConfigureRevisionsOperationResult]):
    def __init__(self, configuration: RevisionsConfiguration): ...
Parameter Type Description
configuration RevisionsConfiguration The revisions configuration to apply

class RevisionsConfiguration:
    def __init__(
        self,
        default_config: RevisionsCollectionConfiguration = None,
        collections: Dict[str, RevisionsCollectionConfiguration] = None,
    ): ...
Property Type Description
default_config RevisionsCollectionConfiguration Optional default settings that apply to any collection Not specified in collections.
collections Dict[str, RevisionsCollectionConfiguration] A Dictionary of collection-specific configurations
The keys are the collection names
The values are the corresponding configurations.
Overrides the default settings for the collections defined.

class RevisionsCollectionConfiguration:
    def __init__(
        self,
        minimum_revisions_to_keep: int = None,
        minimum_revisions_age_to_keep: timedelta = None,
        disabled: bool = False,
        purge_on_delete: bool = False,
        maximum_revisions_to_delete_upon_document_creation: int = None,
    ): ...

Property Type Description
minimum_revisions_to_keep int
  • This number of revisions will be kept per document.
  • Older revisions exceeding this number will be purged upon the next document modification.
  • Default : None = no limit
minimum_revisions_age_to_keep timedelta
  • Limit the number of revisions kept per document by their age.
  • Revisions that are older than this time will be purged upon the next document modification.
  • Default : None = no age limit
    disabled bool
    • fFalse ( Default ) - Revisions will be created and purged according to the configuration.
    • True - No revisions will be created or purged.
    purge_on_delete bool
    • False ( Default ) - Revisions of a deleted document are moved to the Revisions Bin.
    • True - When a document is deleted all its revisions are also deleted.
    maximum_revisions_to_delete_upon_document_creation int
    • The maximum number of revisions to delete upon each document modification.
    • Default : None = no limit,
      all revisions that pend purging will be deleted.