title: Future Configuration Design for Web Application
body: <p>I have a large rails application which configures the setup of a factory.</p>
  
  <p>The application basically have several pages which allow CRUD operations for different entities, and there are many validations that enforce all kinds of dependencies between them. For example: No more than one working station that produces the same product can be placed on the same production line.</p>
  
  <p>We were requested to supply a feature of "future configuration" which we find quite difficult to design a solution for. The idea is to allow the user to make changes that will take affect only tomorrow, or to have a configuration that will be dropped at midnight. </p>
  
  <p>I wonder if there is already a product that implements this functionality so we could learn from it, or are there best practices to approach this issue.</p>
  
  <p>We thought of several solutions but all of them seems to require massive code changes and also seems to be too fragile:</p>
  
  <ol>
  <li><p>Duplicate the DB (MySQL in our case), and have one instance for current setup, and one for tomorrow. At midnight "tomorrow" DB will override current DB. The drawback is having to go and fix each of the dozens of pages, have the option to select the desired DB and handle it on the server side.</p></li>
  <li><p>Keep a stack of future operations to be run at midnight. The drawback is that due to the mass dependencies between the entities, the user cannot know if his action will be successful when it will run at midnight, since the state of the system on midnight is unknown.</p></li>
  <li><p>Add each entity on the DB a start_time and end_time columns and having each object have multiple rows representing different configuration in time. The drawback is editing hundreds of queries and trying to adjust ActiveRecord and its associations to support this state.</p></li>
  </ol>
  
  <p>What is the best approach to tackle this issue?</p>