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
const defaultRevConfig = new RevisionsCollectionConfiguration();
defaultRevConfig.minimumRevisionsToKeep = 100;
defaultRevConfig.minimumRevisionAgeToKeep = TimeUtil.millisToTimeSpan(3600 * 1000 * 24 * 7) // 7 days
defaultRevConfig.maximumRevisionsToDeleteUponDocumentUpdate = 15;
defaultRevConfig.purgeOnDelete = false;
defaultRevConfig.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.

// ==============================================================================
// Define a specific configuration for the EMPLOYEES collection
// This will override the default settings
const employeesRevConfig  = new RevisionsCollectionConfiguration();
employeesRevConfig.minimumRevisionsToKeep = 50;
employeesRevConfig.minimumRevisionAgeToKeep = TimeUtil.millisToTimeSpan(3600 * 1000 * 12);  // 12 hrs
employeesRevConfig.purgeOnDelete = true;
employeesRevConfig.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 PRODUCTS collection
// This will override the default settings
const productsRevConfig   = new RevisionsCollectionConfiguration();
productsRevConfig.disabled = true;

// With this configuration:
// ------------------------
// No revisions will be created for the Products collection,
// even though default configuration is enabled

// ==============================================================================
// Combine all configurations in the RevisionsConfiguration object
const revisionsConfig = new RevisionsConfiguration();
revisionsConfig.defaultConfig = defaultRevConfig;
revisionsConfig.collections = new Map<string, RevisionsCollectionConfiguration>();
revisionsConfig.collections.set("Employees", employeesRevConfig);
revisionsConfig.collections.set("Products", productsRevConfig);

// ==============================================================================
// Define the configure revisions operation, pass the configuration
const configureRevisionsOp = new ConfigureRevisionsOperation(revisionsConfig);

// Execute the operation by passing it to maintenance.send
// Any existing configuration will be replaced with the new configuration passed
await store.maintenance.send(configureRevisionsOp);

Modify configuration

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

// ==============================================================================
// Define the get database record operation:
const getDatabaseRecordOp = new GetDatabaseRecordOperation(documentStore.database);
// Get the current revisions configuration from the database record:
const record = await store.maintenance.server.send(getDatabaseRecordOp);
const revisionsConfig = record.revisions;

// ==============================================================================
// If no revisions configuration exists, then create a new configuration
if (!revisionsConfig) {
    const revisionsConfig = new RevisionsConfiguration();
    revisionsConfig.defaultConfig = defaultRevConfig;
    revisionsConfig.collections = new Map<string, RevisionsCollectionConfiguration>();
    revisionsConfig.collections.set("Employees", employeesRevConfig);
    revisionsConfig.collections.set("Products", productsRevConfig);
}

// ==============================================================================
// If a revisions configuration already exists, then modify it
else {
    revisionsConfig.defaultConfig = defaultRevConfig;
    revisionsConfig.collections.set("Employees", employeesRevConfig);
    revisionsConfig.collections.set("Products", productsRevConfig);
}

// ==============================================================================
// Define the configure revisions operation, pass the configuration
const configureRevisionsOp = new ConfigureRevisionsOperation(revisionsConfig);

// Execute the operation by passing it to maintenance.send
// The existing configuration will be updated
await documentStore.maintenance.send(configureRevisionsOp);

Syntax

const configureRevisionsOp = new ConfigureRevisionsOperation(configuration);
Parameter Type Description
configuration RevisionsConfiguration The revisions configuration to apply

class RevisionsConfiguration
{
    defaultConfig;
    collections;
}
Property Type Description
defaultConfig RevisionsCollectionConfiguration Optional default settings that apply to any collection Not specified in collections.
collections Dictionary<string, 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
{
    minimumRevisionsToKeep;
    minimumRevisionAgeToKeep;
    maximumRevisionsToDeleteUponDocumentUpdate;
    purgeOnDelete;
    disabled;
}

Property Type Description
minimumRevisionsToKeep number
  • This number of revisions will be kept per document.
  • Older revisions exceeding this number will be purged upon the next document modification.
  • Default : null = no limit
minimumRevisionAgeToKeep string
  • 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 : null = no age limit
    maximumRevisionsToDeleteUponDocumentUpdate number
    • The maximum number of revisions to delete upon each document modification.
    • Default : null = no limit,
      all revisions that pend purging will be deleted.
    purgeOnDelete boolean
    • 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.
    disabled boolean
    • false ( Default ) - Revisions will be created and purged according to the configuration.
    • true - No revisions will be created or purged.