Monday, March 30, 2015

List Definition was changed the schema for existing lists!

Until now, I did not know exactly the processing of deployment list definition and there is any changes on each of SharePoint version. I have scenario that I am facing the problem with migration and upgrading list definition. Just is:

I create a list definition based on custom list, because I need to declare all fields, views and the user interface rendering. It's actually basically and for testing purpose only.

The list has only one column named "Title" as default, because I do not know what the next column is to do, so I will upgrade the list def later. I called the list /w version 1.

I modified the list definition schema to add more fields:

Then, from Visual Studio (version 2012) context menu, I click to deploy directly to site. Of course yes if I create a new list base on my list definition having new schema with new 2 columns. But I get the warning that the list definition is created before deployment will be delete the schema and effect to new schema from Visual Studio:

That means all my existing lists will be effected to new schema and they work correctly. The result looks like this:

The question is if I don't use Visual Studio to deploy directly to my server in many scenarios, what happen on my existing lists? for example: some of deployment tools just do copy a schema to physically installation folder and then do reset the IIS or even executed the stsadm command to deploy from wsp. I have tried to do some tests by copy/paste the new schema to feature folder and then execute iisreset command (and deploy by executing stsadm command to deploy wsp). As a result I can still see my 2 new fields in the list settings, however, they did not work correctly. Basically, to access the value of SPListItem, it will throw an exception "Object is not set reference...". It's right because it does not have the default value and it's added after item was created.

The most important thing is if we don't use Visual Studio to upgrade the lisf definition, what do we need to do upgrading the existing lists?

Solutions: After deployment process finish, the all existing lists are effected with the new schema, thus, to determinate the old lists must be based on the other information of the list with specific scenario. For example: properties bag of list/field does not change after deployed the new updates, or checking the dependency to update the old list.

  • fields: add/remove/update by code
  • data: using Batch update command to avoid the performance issue.

  • Do not delete the field and then add the new field if the old field and new field has the same as schema.
  • Move data from old field to new field because it will happen performance issue. In the feature activating/upgrading process, there is not enough time to upgrade the data for large list. 

No comments: