You can download the code for this example here:
OnyxDevTools/onyx-database-samples/model-updates/ ... UpdateIndexDemo.java.
There are 2 parts to this example. The first part is to create an existing database containing the original structure of your model. The second is to modify specific parts of the model and observe how the database handles the updates.
This example consist of both adding and removing an index. In Onyx Database any attribute can be indexed. Removing an index is easy enough but what happens when you add an index to an already existing data model?
Onyx Database supports the adding of an index to an already existing data model. After adding it, it may take some time for the index to re-build. That should happen automatically but you can also trigger it manually.
The first iteration of our data model contains an @Index annotation above the amount attribute.
In order to observe how the database reacts to changes we need to create a script to load sample data before updating the relationship model of the Invoice and Payment entities.
Connect to a new database and seed the data.
The amount index has been removed and we have added an index to the notes attribute
Create a script to reconnect to the database.
Verify we can Query the non indexed amount attribute.
Verify we can Query the indexed notes attribute.
It is not necessicary to manually re-build an index. This should be performed upon initializing the database. The database should automatically detect the change but if you choose to re-build it, the following example will show you how.