title: SqlAlchemy add tables versioning to existing tables
body: <p>Imagine that I have one table in my project with some rows in it.</p>
  
  <p>For example:</p>
  
  <pre class="lang-python prettyprint-override"><code># -*- coding: utf-8 -*-
  import sqlalchemy as sa
  
  from app import db
  
  class Article(db.Model):
      __tablename__ = 'article'
  
      id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
      name = sa.Column(sa.Unicode(255))
      content = sa.Column(sa.UnicodeText)
  </code></pre>
  
  <p>I'm using Flask-SQLAlchemy, so db.session is scoped session object.
  I saw in <a href="https://github.com/zzzeek/sqlalchemy/blob/master/examples/versioned_history/history_meta.py" rel="nofollow">https://github.com/zzzeek/sqlalchemy/blob/master/examples/versioned_history/history_meta.py</a>
  but i can't understand how to use it with my existing tables and anymore how to start it. (I get <code>ArgumentError: Session event listen on a scoped_session requires that its creation callable is associated with the Session class.</code> error when I pass <code>db.session</code> in versioned_session func)</p>
  
  <p>From versioning I need the following:</p>
  
  <p>1) query for old versions of object</p>
  
  <p>2) query old versions by date range when they changed</p>
  
  <p>3) revert old state to existing object</p>
  
  <p>4) add additional info to history table when version is creating (for example editor user_id, date_edit, remote_ip)</p>
  
  <p>Please, tell me what are the best practicies for my case and if you can add a little working example for it.</p>