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.
Why Renaming Attributes Can Be Risky
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.
Best Practices for Renaming Attributes
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:
Step 1: Create a New Attribute
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.
- First, create a new attribute called ExternalID in the same entity.
Step 2: Use a Bootstrap Timer to Migrate Data
Next, create a bootstrap timer to copy data from the old attribute (GoogleID) to the new one (ExternalID).
- Aggregate the data: Set up an aggregate to retrieve all records from the entity.
- Assign values: Loop through the records and assign the value from GoogleID to ExternalID.
- Filter empty values: Add a filter to exclude records where GoogleID is empty to avoid unnecessary updates.
- Empty old attribute: After copying the data, set the GoogleID value to empty to mark the record as processed.
The timer can be scheduled to run automatically after deployment, ensuring that the data migration happens smoothly.
Step 3: Verify the Data Migration
Once the module has been published, it’s important to verify that the data was copied correctly.
- In Service Center: Check that all GoogleID fields are empty and that the ExternalID fields have been populated.
- Using SQL tools: You can also run SQL queries to double-check the migration by counting the number of records with empty GoogleID and filled ExternalID.
Step 4: Deploy Across Environments
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.
Step 5: Remove the Old Attribute
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.
Step 6: Clean Up the Database
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.
Summary of the Process
- Create a new attribute in the entity (e.g., ExternalID).
- Set up a bootstrap timer to copy data from the old attribute to the new one.
- Verify the data migration using filters in Service Center or SQL queries.
- Deploy the changes across environments, ensuring the bootstrap runs in each.
- Remove the old attribute and the bootstrap timer.
- Use DB Cleaner to drop the old attribute from the 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.