Mercurial > libervia-pubsub
comparison sat_pubsub/pgsql_storage.py @ 344:8cf1be9572f8
pgsql: check schema version and exit with a message asking to upgrade if it's not the current one
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 20 Aug 2017 22:54:58 +0200 |
parents | b49f75a26156 |
children | 3bbab2173ebc |
comparison
equal
deleted
inserted
replaced
343:ff8aff4c9b79 | 344:8cf1be9572f8 |
---|---|
53 | 53 |
54 import copy, logging | 54 import copy, logging |
55 | 55 |
56 from zope.interface import implements | 56 from zope.interface import implements |
57 | 57 |
58 from twisted.internet import reactor | |
58 from twisted.words.protocols.jabber import jid | 59 from twisted.words.protocols.jabber import jid |
59 from twisted.python import log | 60 from twisted.python import log |
60 | 61 |
61 from wokkel import generic | 62 from wokkel import generic |
62 from wokkel.pubsub import Subscription | 63 from wokkel.pubsub import Subscription |
72 psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY) | 73 psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY) |
73 | 74 |
74 # parseXml manage str, but we get unicode | 75 # parseXml manage str, but we get unicode |
75 parseXml = lambda unicode_data: generic.parseXml(unicode_data.encode('utf-8')) | 76 parseXml = lambda unicode_data: generic.parseXml(unicode_data.encode('utf-8')) |
76 PEP_COL_NAME = 'pep' | 77 PEP_COL_NAME = 'pep' |
78 CURRENT_VERSION = '2' | |
77 | 79 |
78 | 80 |
79 def withPEP(query, values, pep, recipient): | 81 def withPEP(query, values, pep, recipient): |
80 """Helper method to facilitate PEP management | 82 """Helper method to facilitate PEP management |
81 | 83 |
114 } | 116 } |
115 } | 117 } |
116 | 118 |
117 def __init__(self, dbpool): | 119 def __init__(self, dbpool): |
118 self.dbpool = dbpool | 120 self.dbpool = dbpool |
121 d = self.dbpool.runQuery("SELECT value FROM metadata WHERE key='version'") | |
122 d.addCallbacks(self._checkVersion, self._versionEb) | |
123 | |
124 def _checkVersion(self, row): | |
125 version = row[0].value | |
126 if version != CURRENT_VERSION: | |
127 logging.error("Bad database schema version ({current}), please upgrade to {needed}".format( | |
128 current=version, needed=CURRENT_VERSION)) | |
129 reactor.stop() | |
130 | |
131 def _versionEb(self, failure): | |
132 logging.error("Can't check schema version: {reason}".format(reason=failure)) | |
133 reactor.stop() | |
119 | 134 |
120 def _buildNode(self, row): | 135 def _buildNode(self, row): |
121 """Build a note class from database result row""" | 136 """Build a note class from database result row""" |
122 configuration = {} | 137 configuration = {} |
123 | 138 |