Open grtjn opened 7 years ago
These get uploaded to the schemas database. Seems to make sense to attach to deploy schema, but might require specific logic..
Similar like I commented on #645, might be worth auto-detecting file format based on introspection. XML has this at the root: <template xmlns="http://marklogic.com/xdmp/tde">
, and JSON must have something similar..
Hmm, thought.. how about doing the introspection after loading in schema db using xqy or sjs?
Not the prettiest code, but this seemed to work:
def deploy_schemas
original_deploy_schemas
logger.info "Generating TDE templates for models:"
r = execute_query(
%Q{
xquery version "1.0-ml";
import module namespace es = "http://marklogic.com/entity-services" at "/MarkLogic/entity-services/entity-services.xqy";
import module namespace tde = "http://marklogic.com/xdmp/tde" at "/MarkLogic/tde.xqy";
for $entity-doc-uri as xs:string? in cts:uris((), (), cts:directory-query("/entities/", "infinity"))
let $t := es:extraction-template-generate(fn:doc($entity-doc-uri))
let $path := fn:substring-before($entity-doc-uri, ".json") || ".xml"
return (
$entity-doc-uri,
tde:template-insert($path, es:extraction-template-generate(fn:doc($entity-doc-uri)))
)
},
{ :db_name => @properties["ml.content-db"] }
)
r.body = parse_body r.body
logger.info r.body
logger.info ""
logger.info "Applying custom TDE templates:"
query = File.read ServerConfig.expand_path("#{@@path}/../tde/tdeDataStore.xqy")
r = execute_query(
query,
{ :app_name => @properties["ml.app-name"] }
)
r.body = parse_body r.body
logger.info r.body
logger.info ""
change_permissions(@properties["ml.schemas-db"])
end
Includes inserting and validating templates. http://docs.marklogic.com/tde