Fixed database access issues, and installer question list

This commit is contained in:
Mike Young
2019-12-31 21:13:52 -05:00
parent a19401c1aa
commit da133c4197
8 changed files with 37 additions and 23 deletions

View File

@@ -12,8 +12,7 @@ from .config import Config
class Storage:
"""Contains all methods for system storage"""
def __init__(self, db_pointer, config):
# self.db_file = db_pointer
def __init__(self, config):
self.sql = config.catalogue_db
self.user = config.user
self.password = config.password
@@ -22,8 +21,27 @@ class Storage:
self.db = psycopg2.connect(
database=self.sql, user=self.user, password=self.password, host=self.db_host
)
self.config = config
self.cursor = self.db.cursor()
# self.create_tables()
def check_ownership(self, table=None):
if table is None:
table = "books"
_q = "SELECT * FROM books"
try:
self.cursor.execute(_q)
except Exception as e:
breakpoint()
if e.pgcode == "42501":
_q = """ALTER TABLE public.books OWNER to pyshelf;"""
self.close()
set_perms = Storage(self.config)
try:
set_perms.cursor.execute(_q)
set_perms.close()
except Exception as e:
print(e)
set_perms.close()
def create_tables(self):
"""Create table structure"""