konung
konung

Reputation: 7038

Updating enum in Rails ActiveRecord model by end user

Looking for the best strategy in the following scenario.

Consider Rails 4 online store app that has model Order that has a status

class Order 
  enum status: [ :placed, :processed, :shipped ]
end

We ship the app to the customer and a month later they come back to us saying the want to add one more status - backordered. We go in and update code / test / and deploy.

class Order 
  enum status: [ :placed, :processed, :shipped, :backordered ]
end

A few months later they come back again and want one more status - :work_in_progress . Etc

In the past we avoided the problem by having an aggregate model - Status - that would be an STI model and hold things like

OrderStatus < Status  

and

CustomerStatus < Status  

This makes is trivial for customer to add statuses or change names of the status, but it makes for slower SQL look ups and cumbersome joins especially on complex queries.

So I was wondering is there a good strategy of dealing with this problem? Right now we have a combination of two - on the model we don't think customer would want to add / remove status - we keep it enum, otherwise we do belongs_to to a some kind of Status / Category model.

Upvotes: 2

Views: 1101

Answers (1)

zetetic
zetetic

Reputation: 47548

a month later they come back to us saying the want to add one more status

Changing one line of code, even if it happens once a month, should not be a painful experience. You already have the best strategy: when the customer asks for a change, grit your teeth, add the new value, test and deploy. If that is too onerous I'd say the problem lies with the deployment process rather than the customer.

After a few rounds of this the customer will run out of new values to add and move on to other annoying requests.

Upvotes: 2

Related Questions