mountetna / magma

Data server with friendly data loaders
GNU General Public License v2.0
5 stars 2 forks source link

Support rename_attribute #171

Open graft opened 4 years ago

graft commented 4 years ago

If we want to change the name of an existing attribute, we need to rename the column. In the future we might decouple these things; the data table column name could be added to the attributes table, so that the reference to the column is independent of the name of the attribute. However, currently the attribute associates with the column strictly by name.

To support rename_attribute we need only:

  1. change the entry in the attributes table
  2. update the Magma::Model.attributes
  3. Migrate the column to its new name.

Since we're fortunately not changing the type of the column or even removing the column from the model, the data itself remains intact throughout and is still associated in the same place. Therefore this action is not actually destructive and we don't need to do anything else.

Here we should only have to validate (after correctly finding the attribute) that new_attribute_name is in snake_case and doesn't collide with an existing attribute.

graft commented 4 years ago

Of note: some dictionaries might refer to the attribute by attribute_name. If these are not renamed in this operation, they will fall out of sync and break. However, it might not be easy to find all of the dictionary names and update them.