My team is debating how to transition a portion of our Rails application to allow "drafts". For simplicities sake, we can imagine a Post object where we want to allow a kind of draft mode.
Our real model contains, say, roughly 20 fields and 5 has_many relationships. There are some reasonably complex business rules (i.e., content can't be changed after a Post is delivered), and a state machine (Posts are pending, sending, then delivered).
class Post string content enum content_type date deliver_on enum delivery_state has_many customer_group_segments end
Two options being considered, but we are open to more. One is to duplicate all the existing tables (i.e.,
customer_group_segment_drafts, etc). The second is to include a kind of
is_draft field on the post.
The first option would separate all the data, but we'd need to consider sharing business logic between all models. And in the case of the draft, all of the validation rules would be optional until you tried to convert a Draft to a Post. And we'd also need to create a kind of transfer mechanism, etc...
The second option would remove all constraints from the underlying tables. We'd also need to make some kind of mode system, to ensure validation only kicks in where appropriate. And we'd also need to implement various checks to ensure, for example, that we don't try and deliver a draft.
There is a similar, but older question. I'm curious of there are any new opinions. Any ideas, observations, or working examples would be great!