Chapter 8. Data Migration

Table of Contents

8.1. Summary of scenarios
8.1.1. Table of situations
8.1.2. Procedures with JCR Storage on filesystem
8.1.3. Procedures with JCR Storage on SQL
8.1.4. Procedure with SQL Storage

This chapter describes how to modify existing document types.

8.1. Summary of scenarios

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)

8.1.1. Table of situations

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 / BackendJackRabbit on FileSystemJackRabbit on SQLSQL Storage
Add a schemaYES (1.2.1)YES (1.3)YES (1.4.1)
Remove a schemaNO (1.2.2)YES (1.3)YES (1.4.2)
Add a fieldYES (1.2.1)YES (1.3)YES (1.4.2)
Remove a fieldNO (1.2.2)YES (1.3)YES (1.4.2)
Modify field typeNO (1.2.3)YES (1.3)YES (1.4.3)

8.1.2. Procedures with JCR Storage on filesystem

8.1.2.1. Adding field / schema

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.

8.1.2.2. Removing field /schema

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.

8.1.2.3. Modifying a field type

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.

8.1.3. Procedures with JCR Storage on SQL

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.

8.1.4. Procedure with SQL Storage

8.1.4.1. Adding a schema

In the SQL storage, adding a schema is natively supported. No extra operation is needed to take into account the new schema.

8.1.4.2. Adding a field, removing field /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 ...)

8.1.4.3. Modifying a field type

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