mountetna / magma

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

Configure Magma::Attribute sti key_map #198

Closed alimi closed 3 years ago

alimi commented 3 years ago

Without a key_map, the Sequel single table inheritance plugin will use the model_map to insert values into the database. For Magma::Attribute, this resulted in types being inserted as Ruby classes (i.e., Magma::IntegerAttribute) instead of strings (i.e., integer). By configuring key_map, we can make sure Magma::Attribute types are inserted as strings.

Info on the plugin can be found here: http://sequel.jeremyevans.net/rdoc-plugins/classes/Sequel/Plugins/SingleTableInheritance.html.

alimi commented 3 years ago

Also, if there's a bunch of records that need to be updated in prod you can run something like the following on the console.

Magma::Attribute.each do |attribute|
  attribute.update(type: attribute.type.match("Magma::(.*)Attribute")[1].underscore)
end

You'll have to restart the server though so the cached attributes in memory get reloaded.