Sana Assistant (online)
Table of Contents

Upgrading client-side API data records

This is a continuation of the upgrade implementation tutorial.

If you're using client-side in your extension to store your data, you may need to implement upgrades for your data records, created in previous versions of the add-on.

Step 1: Implement upgrade class

Create upgrade class in 'new' version folder

Since we don't need to implement any 'old' and 'new' models in 'v1.0.0' and 'v1.0.1' folders, we should start with 'v1.0.1' only ('v1.0.0' is not needed):

Upgrades Folder

Create a new class in your 'Upgrades/v1.0.1' folder:

Upgrade Class

Fix namespaces

Don't forget to change messy v1._0._1 namespace name generated by the Visual Studio to more readable v1_0_1:

Inherit from DataRecordsUpgrade

Now inherit your newly added class from Sana.Extensions.Upgrades.DataRecordsUpgrade abstract class:

Upgrade Class Inherited

Implement abstract members

Because the base DataRecordsUpgrade class is abstract, you now need to implement it's abstract members.

Implement UpgradeTo property

This is a property which tells Sana Commerce Cloud to which version this upgrade class upgrades the data to. So in our case we're creating upgrade to version 1.0.1, so our UpgradeTo should indicate exactly that:

Upgrade Class UpgradeTo Property

Implement UpgradeDataRecord method

This is the actual upgrade implementation. Implement what you need to upgrade in your data record from previous version to current (from 1.0.0 to 1.0.1).

You can read more about what exactly you can do in the upgrade with examples in a separate article.

Note that unlike in the previous upgrade tutorials, there is no 'old' and 'new' model involved. There is only one parameter in the UpgradeDataRecord method, which is UpgradableDataRecordModel and you can change its Data property:

dataRecord.Data

You can also access the ID of the data record in case you need it, but you cannot modify its value - the property is read-only:

dataRecord.Id

In our example we will simply append some dummy text to our data:

Upgrade Class Complete

Step 2: Test it

When your upgrade has been implemented, you can build your extension add-on and update it in Sana Admin (Apps > Add-ons > click Update on your add-on). After the newest version has been installed, proceed to the Graph API to check the data record. Let's assume we have a record with ID: '7':

Before the upgrade, version 1.0.0:

Graph API Before

After the upgrade, version 1.0.1:

Graph API After

Next version

When you implement the next version of your extension, in our example it will be version 1.0.2, you simply add a new 'Upgrades/v1.0.2' folder and continue from Step 1: Implement upgrade class:

Data Records Upgrade v1.0.2

Conclusion

That's it, the upgrade of data records is complete.

Back to general implementation tutorial