At one point, I understand that some entities and their attributes need to be renamed. The names are boring and do not reflect the dramatic nature of the code. How can this be done in the most correct way and what problems can arise? (Cuba Studio + Idea)
If you have already written some code working with your entities, I’d recommend using IntelliJ for refactoring. It can correctly find all usages in source code, screens descriptors and configuration files and usually renaming does not cause any problems. Renaming database table and column names will probably require search-and-replace in entity source and in database init scripts.
Just in case, close the project in Studio and reopen after renaming.
Studio also can rename entities and attributes but it refactors only project elements that it is aware of, like view definitions and data-aware components linked to the changed attributes. Studio cannot refactor your source code, so it’s better to rename in Studio only on the initial stage of development when the data model has just been created.
I found the following approach working fine:
Make a backup of your code (or commit)
Make a backup of your database
Close the project in Cuba studio
Refactor property name through IntelliJ
– Open entity class
– Select property and click SHIFT-F6
– Enter new name
– Review proposed refactoring (exclude what should not be renamed)
– Let IntelliJ refactor the code
Rename property in database
– Open the project in Cuba studio
– Open object editor
– Select attribute
– Rename column name and save object
– Start your application
– Cuba will prompt to update the database - DO NOT DO THIS
– Instead, open DB manager
– Alter the modification script from adding and dropping to alter column:
ALTER TABLE table_name RENAME COLUMN old_column TO new_column
– Save modified script
– Update database from Cuba studio
Start your application
Everything should be fine now. If something went wrong, restore your backups and try to correct.