Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/postgresql/db.py
Show All 21 Lines | |||||
def jsonize(d): | def jsonize(d): | ||||
return _jsonize(dict(d) if d is not None else None) | return _jsonize(dict(d) if d is not None else None) | ||||
class Db(BaseDb): | class Db(BaseDb): | ||||
"""Proxy to the SWH DB, with wrappers around stored procedures""" | """Proxy to the SWH DB, with wrappers around stored procedures""" | ||||
current_version = 182 | |||||
def mktemp_dir_entry(self, entry_type, cur=None): | def mktemp_dir_entry(self, entry_type, cur=None): | ||||
self._cursor(cur).execute( | self._cursor(cur).execute( | ||||
"SELECT swh_mktemp_dir_entry(%s)", (("directory_entry_%s" % entry_type),) | "SELECT swh_mktemp_dir_entry(%s)", (("directory_entry_%s" % entry_type),) | ||||
) | ) | ||||
@stored_procedure("swh_mktemp_revision") | @stored_procedure("swh_mktemp_revision") | ||||
def mktemp_revision(self, cur=None): | def mktemp_revision(self, cur=None): | ||||
pass | pass | ||||
▲ Show 20 Lines • Show All 1,498 Lines • ▼ Show 20 Lines | def _get_random_row_from_table(self, table_name, cols, id_col, cur=None): | ||||
LIMIT 1 | LIMIT 1 | ||||
""".format( | """.format( | ||||
cols=", ".join(cols), table=table_name, id_col=id_col | cols=", ".join(cols), table=table_name, id_col=id_col | ||||
) | ) | ||||
cur.execute(query, (random_sha1, random_sha1)) | cur.execute(query, (random_sha1, random_sha1)) | ||||
row = cur.fetchone() | row = cur.fetchone() | ||||
if row: | if row: | ||||
return row[0] | return row[0] | ||||
dbversion_cols = ["version", "release", "description"] | |||||
def dbversion(self): | |||||
with self.transaction() as cur: | |||||
cur.execute( | |||||
f""" | |||||
SELECT {', '.join(self.dbversion_cols)} | |||||
FROM dbversion | |||||
ORDER BY version DESC | |||||
LIMIT 1 | |||||
""" | |||||
) | |||||
return dict(zip(self.dbversion_cols, cur.fetchone())) | |||||
def check_dbversion(self): | |||||
dbversion = self.dbversion()["version"] | |||||
if dbversion != self.current_version: | |||||
logger.warning( | |||||
"database dbversion (%s) != %s current_version (%s)", | |||||
dbversion, | |||||
__name__, | |||||
self.current_version, | |||||
) | |||||
return dbversion == self.current_version |