code: def get_version(db, name):
      
      try:
          result = db.fetchone(GET_VERSION_SQL, dict(name=name))
      except psycopg2.ProgrammingError as exc:
          if 'does not exist' in str(exc):
              return recreate(db, name)
          raise
      else:
          if result is None:
              set_version(db, name, 0, 0)
              return (0, 0)
          version = result['version']
          return unpack_version(version)
docs: Query database and return migration version. WARNING: side effecting
      function! if no version information can be found, any existing database
      matching the passed one's name will be deleted and recreated.
  
      :param db:      connetion object
      :param name:    associated name
      :returns:       current migration version