Table of Contents
This chapter describes how to modify existing document types.
Five different situations can happen when you want to make evolve your data models.
adding a new schema to a document type
removing a schema from a document type definition
adding a new field to an existing schema
removing a field from a schema
changing field type (from integer to string for example)
This table sums up how data migration are handled : YES if the operation is supported, NO if not and into brackets, reference to the relative procedure.
| Action / Backend | JackRabbit on FileSystem | JackRabbit on SQL | SQL Storage |
|---|---|---|---|
| Add a schema | YES (1.2.1) | YES (1.3) | YES (1.4.1) |
| Remove a schema | NO (1.2.2) | YES (1.3) | YES (1.4.2) |
| Add a field | YES (1.2.1) | YES (1.3) | YES (1.4.2) |
| Remove a field | NO (1.2.2) | YES (1.3) | YES (1.4.2) |
| Modify field type | NO (1.2.3) | YES (1.3) | YES (1.4.3) |
When adding a schema to a document type or a field to a schema,
you need to rebuild JCR nodetypes which are defined in
nodetypes/custom_nodetypes.xml. The force
reloading is done by setting the forceReloadTypes
attribute in
$JBOSS_HOME/server/default/deploy/nuxeo.ear/config/default-repository-config.xml
to true:
<repository name="default"
factory="org.nuxeo.ecm.core.repository.jcr.JCRRepositoryFactory"
securityManager="org.nuxeo.ecm.core.repository.jcr.JCRSecurityManager"
forceReloadTypes="true">
...
</repository>
Keep in mind that this setting could not be applied in a production environment.
Removing an attribute or a schema is not supported by the JCR backend. When JCR gets a nodetype related to a document, it tries to give a type to each properties. If a field or a schema is removed, JackRabbit cannot associate a type to the node and it raises the following error:
Exception: javax.jcr.nodetype.ConstraintViolationException. message: no matching property definition found for MyCustomType
If you do not want to use a schema or a field any more, keep them in your doctype / schema definition and never use them in your interface.
Creating new documents with new field type definition is possible.
However all previously created documents will not be
modifiable.anymore: if you try to save your modifications, you will
get a NullPointerException caused by JCR which will
not be able to retrieve the field with the new given type. At reading,
all document attributes from the schema containing the modified field
will be empty.
These use cases were tested on JCR Storage with PostgreSQL. for data persistence.
All manipulations on document structure are supported without changing any configuration file.
In the SQL storage, adding a schema is natively supported. No extra operation is needed to take into account the new schema.
Adding a new field, removing a field or a schema are supported operations in the SQL storage. They need to modify the database with SQL queries (Alter ...)
Modifying a field type is also supported in the SL storage: this operation needs some SQL commands to be effective:
first, create a new column with the desired type
then, populate your column by casting value from previous type to new one
remove old column
finally, alter table to rename new column with field name