You can download the code for this example here:
OnyxDevTools/onyx-database-samples/model-updates/ ... UpdateFieldDemo.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 particular change involves adding an attribute, removing an attribute, and changing an attribute type. In all cases the database handles a lightweight migration.
There are some inherent flaws in the original data model. First, there are some missing fields and the precision of an integer is not scalable enough for a primary key. The primary key should be of type long.
In order to observe how the database reacts to changes we need to create a script to load sample data before updating the model so that we may preserve the format of the entities before updating the model.
Connect to a new database and seed the data.
The account entity has several changes including added, removed, and changed attributes.
Changing attribute types is supported if the original type can be converted to the new type. You may not be able to take advantage of the lightweight migration if you were to change the type from a long to an int. Another example would be attempting to convert a String to a numeric value. In either case you will not be able to cast the original value to the new type.
Create a script to reconnect to the database.
Retrieve the account using a long rather than int.
Our goal is to bring about change by enabling people to use simple and quality software in order to make sad engineers happy.
Copyright ©2017 Onyx Development Tools, LLC. All rights reserved.