title: Append only jsonb column in Rails + Postgres
body: <p>Is anyone using Rails 4.x or Rails 5.x and the Postgres (9.4+) <code>jsonb</code> column? I understand the benefits of using jsonb + Postgres - you get to mix schemaless data with structured data. Some might call this a happy medium.</p>
  
  <p>We've noticed it's easy to (accidentally or intentionally) overwrite <code>jsonb</code> data when updating a row. Has anyone seen any techniques to make the <code>jsonb</code> column append-only?</p>
  
  <p>Suppose a row has a<code>jsonb</code>column, let's call it "questionnaire". The questionnaire column has the following lifecycle:</p>
  
  <ol>
  <li>starts as <code>null</code></li>
  <li>some json is saved (via <code>UPDATE</code> operation)</li>
  <li>another <code>UPDATE</code> operation occurs to append more json this time it's a json array</li>
  <li>another <code>UPDATE</code> operation occurs, but this time with "{}" which is valid json</li>
  <li>all the data stored in "questionnaire" is now invalid. </li>
  </ol>
  
  <p>This is bad because we have essentially lost all data.</p>
  
  <p>More broadly, how have others implemented append only tables (or columns) in Rails or Postgres? Is this problem best tackled at the db layer or application layer?</p>
  
  <p>Appreciate the thoughts. Thanks in advance!</p>