Search code examples
marklogic

How to deploy TDE templates via ml-gradle


Is it possible to deploy TDE templates by running method tde.templateInsert()?

I need to validate templates before deployment.

How to disable templates before redeploying new ones or updating existing ones?


Solution

  • Yes, you can deploy TDE templates with tde.templateInsert().

    It is provided as a convenience method that will first validate (which you can also perform by using tde:validate()), then inserts the template into the schema database, and then reindex matching documents.

    If you are deploying templates with the same URI, then you can re-insert the template.

    If you have a set of templates that are no longer needed and want to drop, you should set them as disabled and allow for the matching docs to be reindexed.

    You can see how many documents still need to be reindexed by executing the following:

    xdmp:forest-counts(
      xdmp:forest("Documents"),
      ("reindex-tde-templates", "reindex-deleted-tde-templates")
    )
    

    When reindexing has completed, those TDE templates can safely be deleted. You can delete a Template using xdmp:document-delete().

    If you delete the Template without disabling, you may be left with some wasted space from obsolete indexes.

    https://docs.marklogic.com/guide/app-dev/TDE#id_94831

    Accidental deletion of a template can be fixed by:

    • Reinserting the template in a disabled state.
    • Reusing the same template document URI for a new template.
    • Manually reindexing the database.

    If you are using ml-gradle for your deployments, then you just need to put your TDE templates under the tde directory of the schema database directory. i.e. /src/main/mySchemaDB/tde/foo.tde. Take a look at the ml-gradle examples/schemas-project for a practical example.