Storage Custom Entity: How to add a field and not break everything? Default field values and how to upgrade storage structure on prod?

Hi, community!

I’m building an app using Storage with Custom Entities inside as my DB. Something shocking happened to me when I was faced with a simple task: Add a field to my Custom Entity.

Here are 2 major problems that appeared:

1. No mechanism to set default values once the field is added
How could I set default values for existing data on my Storage? I need to handle a trigger by some event the storage structure was updated and some migration script needs to be run during deployment.

Something very similar already exists - app:upgrade event once app major version updated, but updating custom entity storage structure in manifest doesn’t trigger any major version update and any custom event as well.

So, once I added a new field to my app storage, how can the already installed Forge app instance on the client’s project handle the migration script to set these fields with default values by some logic on their DB?

I could do some wrapper to my Storage Get requests and check if the field has no value - then provide some default one, save, and then process the request, but feels like a wrong way to handle this case.

2. Are there plans to enable updating the Custom Entity data structure in the future?
I mean to be more specific:

  • Update data type
  • Remove fields
  • Remove indexes

Currently, to handle this type of entity change I found only 2 major ways:

  1. Create a “juicy” new custom entity storage with an updated structure and name “messages_v2”.
    Cons: Extra DB “tables”, code garbage, and Forge app limits for such tricks. In addition, complete data copying with an unknown trigger to perform (see question 1)
  2. Create a new app with a clear history and updated storage structure.
    Cons: Forge limit of 50 apps and a completely new app on Marketplace each time with all clients lost ^.^

I feel like it’s impossible to be that way because it means no apps with no insanity in support every new release and DB update of Forge app possible, which will make the whole concept of Storage Custom entity - questionable.

Please, somebody, say I’m wrong :pray:

P.S. If it’s possible, is there a way to ask to update Custom Entity storage documentation with this response later?

1 Like

Is there a way to ask somebody from Forge developers to respond?

It is no problem to wait another week, but it feels like a blocker for Storage Custom Entity usage as far as I have no idea how to maintain future entity changes on prod with this approach.

P.S. If anyone in the community uses Storage Custom Entity on their prod apps - would be extremely glad for a short tip on how to update entity structure on the released app and launch migration script? :melting_face:

Ping. @AtlassianSupport can you point me to the correct place to ask? It seems like the Community forum is not working :frowning:

You could open a support ticket here: https://developer.atlassian.com/support

I have no inside knowledge, but your workaround for 1 seems reasonable to me and I doubt there are any plans in the near future to allow updates to custom entity types.

2 Likes