Advertisement
peter9477

sqlite schema version check

Nov 21st, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1.     def check_schema(self):
  2.         if self.debug:
  3.             print('storage: check_schema')
  4.  
  5.         try:
  6.             result = self.execute('get_metadata', name='version').fetchone()
  7.             self.version = int(result[0])
  8.             if self.debug:
  9.                 print('version read as', self.version)
  10.  
  11.         except (sqlite3.OperationalError, TypeError):
  12.             self.version = 0
  13.             if self.debug:
  14.                 print('version set to', self.version)
  15.  
  16.         for schema in (s for s in self._doc.iter('schema')
  17.             if int(s.get('version')) > self.version
  18.             ):
  19.             self.version = self.upgrade_schema(schema)
  20.             if self.debug:
  21.                 print('upgraded schema, ver', self.version)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement