Renaming an attribute within an entity in OutSystems might seem like a straightforward task, but it requires careful attention to database integrity. Simply renaming an attribute in Service Studio does not automatically update your database, which could lead to missing data or other complications. In this dev tip, OutSystems Developer Chris Adams walks us through the correct process of renaming an attribute while ensuring that data remains intact and the database is kept clean.
Before diving into the steps, it's important to understand why renaming an attribute in OutSystems can be risky. When you rename an attribute in Service Studio, OutSystems creates a new empty column in the database for the renamed attribute. The data from the old column remains in the database but is no longer visible within Service Studio. This means that renaming without proper planning can result in your data becoming "invisible" and no longer usable in your applications.
While it’s best to avoid renaming attributes whenever possible, especially when the change needs to be applied across multiple environments, there are times when renaming is necessary. For these scenarios, Chris suggests following a specific process to maintain database integrity:
Let’s say you have an entity for account configurations and you initially named the attribute GoogleID. Now you want to rename it to ExternalID to use it for other services.
Next, create a bootstrap timer to copy data from the old attribute (GoogleID) to the new one (ExternalID).
The timer can be scheduled to run automatically after deployment, ensuring that the data migration happens smoothly.
Once the module has been published, it’s important to verify that the data was copied correctly.
If the attribute rename needs to be applied across multiple environments, now is the time for your first deployment. The bootstrap timer will run in each environment to copy the data automatically.
Once you’ve confirmed that the data migration worked correctly across all environments, you can remove the old GoogleID attribute. At the same time, delete the bootstrap timer as it’s no longer needed. Publish the module to complete this step.
Even though the GoogleID attribute has been removed from Service Studio, the column may still exist in the database. This is where the DB Cleaner Forge component comes in handy. Use DB Cleaner to drop the now-unused GoogleID column from the database. This step helps maintain a clean and optimized database.
By following these steps, you can safely rename attributes in OutSystems without risking data integrity and ensure your database remains clean.
Renaming attributes in OutSystems requires careful attention to avoid data loss and maintain database integrity. By using the process outlined here, including creating a new attribute, using a bootstrap timer to migrate data, and leveraging tools like DB Cleaner, you can ensure a smooth transition.
Want to learn more valuable Dev Tips? Sign up for our newsletter and stay updated with the latest insights! Also, don't forget to check out our upcoming OutSystems courses to scale your career.
[custom_like]