Content Type Change Management

If you have created (and published) entries using a content type, making changes to the content type schema may result in data loss of existing entries.

There are, however, certain guidelines, following which you can make changes to the content type, without losing any data or impacting the content of your live site or app.

In this document, we will discuss the various types of changes you can possibly make to a content type schema (listed below), and the guidelines you need to follow to make such changes safely.

Content Type Change Management.jpg

To understand these scenarios, we will consider an example. You have a content type named Product and there are several fields within the Product content type:

  • Name: Single line textbox (String data type)
  • Price: Single line textbox (String data type)
  • Description: Rich Text Editor (String data type) for displaying product’s description

You have created and published multiple entries for the Products content type. Now let’s look at the changes that you want to perform and the steps to be followed to perform the changes.

Add a new field to an existing content type

There is no data loss when adding a new field since you are not modifying or deleting any existing fields that already have data.

Let’s say you want to add a ‘Manufacturer’ (Single line textbox) field to the Product content type. To do this, perform the following steps:

  1. Edit the content type
    Go to the stack and edit the Products content type.
  2. Add the new field
    Drag and drop a single line textbox field and name it Manufacturer.
  3. Publish entries on staging
    Edit all existing entries and add data in the new field. Then, publish them on staging.
  4. Make changes to UI code
    To display the content of this field, add the UID of this new field to your UI code. Push the changes on staging and check if it fetches the content of the new field.
  5. Publish/push on production
    If everything is working as expected on staging, publish the entries and push the code on production.

Edit an existing field in an existing content type

When you edit a field in an existing field of an existing content type, there is a possibility of data loss.

For example, if you want to change the data type of Price from string to number, all the data that exists within the Price (String data type) field will be lost.

Being cautious and following the steps below will help you preserve the data while editing a field.

  1. Add a new field
    Edit the Products content type and add a new field: Price_new. Now you have a Price field and a Price_new field in your content type.
  2. Edit entries
    Manually edit all the existing entries, and enter new data in the Price_new field. Keep the data of the Price field as is.
  3. Publish entries
    Publish these entries on your staging environment to ensure mapping is successful.
  4. Make changes to UI code
    Now, replace the price uid with price_new uid in your presentation code. This will ensure that your site/app fetches the new field’s content.
  5. Test and publish
    Deploy the code on staging, to check if your site/app fetches the new data. If everything seems proper, first publish the entries on production and then deploy the code on production.
  6. Delete the old field
    Once you have ensured that everything is working fine, delete the Price field from your content type and you are done.

Delete a field from a content type

When you delete a field from an existing content type, the data of that field will be lost permanently. Let’s consider you want to delete the Description field from the Product content type.

The following steps will help you achieve these goals.

  1. Make changes to UI code
    If you have used the description uid anywhere in your code, remove it, and push the changes on your staging environment.
  2. Delete the field
    Edit the Product content type, and delete the Description field.
  3. Publish entries
    After making changes to the content type, you will notice that the field no longer exists in your existing entries. Publish these entries on staging.
  4. Test on staging
    Check if everything is working as expected on the staging environment.
  5. Publish/push on production
    If everything is working as expected on your staging site, publish the entries and push the code on your production environment.

Make major changes to the schema of a content type

If you plan to make major changes to the schema of a content type, follow the steps given below to ensure there is no data loss.

  1. Create a copy of the content type
    Create a new content type which will be the replica of the content type you want to edit.
  2. Edit the schema
    Make changes (add or remove fields) to this new content type.
  3. Create entries
    Now, create new entries for this content type. Publish these entries on staging.
  4. Make changes to UI code
    In your presentation code, use the uids of the fields of the new content type. This will ensure that your site/app refers to the new fields instead of the old fields.
  5. Test on staging
    To check if the data has been mapped correctly, push the UI code on your staging environment. Confirm if it is good to go live.
  6. Publish/push on production
    Once everything is working fine on staging, push the entries and push the code on production.
  7. Delete old content type
    You can now safely delete the old content type.

Was this article helpful?
top-arrow