forked from importers/git-importer
fixed formatting and other suggestions
This commit is contained in:
37
lib/db.py
37
lib/db.py
@@ -22,20 +22,19 @@ class DB:
|
||||
|
||||
def schema_version(self):
|
||||
# create a cursor
|
||||
cur = self.conn.cursor()
|
||||
with self.conn.cursor() as cur:
|
||||
|
||||
# execute a statement
|
||||
try:
|
||||
cur.execute("SELECT MAX(version) from scheme")
|
||||
except psycopg2.errors.UndefinedTable as error:
|
||||
cur.close()
|
||||
self.close()
|
||||
self.connect()
|
||||
return 0
|
||||
# execute a statement
|
||||
try:
|
||||
cur.execute("SELECT MAX(version) from scheme")
|
||||
except psycopg2.errors.UndefinedTable as error:
|
||||
cur.close()
|
||||
self.close()
|
||||
self.connect()
|
||||
return 0
|
||||
|
||||
db_version = cur.fetchone()
|
||||
db_version = cur.fetchone()
|
||||
|
||||
cur.close()
|
||||
return db_version[0]
|
||||
|
||||
def close(self):
|
||||
@@ -170,15 +169,13 @@ class DB:
|
||||
if (schema_version + 1) not in schemes:
|
||||
return
|
||||
try:
|
||||
cur = self.conn.cursor()
|
||||
# create table one by one
|
||||
for version, commands in schemes.items():
|
||||
if version <= schema_version:
|
||||
continue
|
||||
for command in commands:
|
||||
cur.execute(command)
|
||||
# close communication with the PostgreSQL database server
|
||||
cur.close()
|
||||
with self.conn.cursor() as cur:
|
||||
# create table one by one
|
||||
for version, commands in schemes.items():
|
||||
if version <= schema_version:
|
||||
continue
|
||||
for command in commands:
|
||||
cur.execute(command)
|
||||
# commit the changes
|
||||
self.conn.commit()
|
||||
except (Exception, psycopg2.DatabaseError) as error:
|
||||
|
Reference in New Issue
Block a user