Renamed tables in DB_adapter

Renamed the database tables to reflect the newest schema in the scripts. Changed the db_adapter calls to fit.
dev
Peery 2 years ago
parent 8a30dc2cb9
commit 2b4cac949a

@ -5,8 +5,9 @@ from psycopg2.errorcodes import UNIQUE_VIOLATION
class DBAdapter:
EXPECTED_TABLES = ['art', 'artist', 'tag', 'topic', 'presence', 'artist_topic', 'art_author',
'art_tag', 'tag_alias', 'tag_implication', 'tag_category']
EXPECTED_TABLES = ['art', 'artist', 'tag', 'topic', 'presence', 'artist_to_topic', 'art_to_presence',
'art_to_tag', 'tag_alias', 'tag_implication', 'tag_category', 'art_collection',
'art_to_art_collection']
def __init__(self, user: str, password: str, host: str = "localhost", port: int = 5432, database: str = "artnet"):
self.db = None
@ -91,7 +92,7 @@ class DBAdapter:
continue
d = {"id": ID, "tag": self.get_tag_ID(tag)}
try:
self.db_cursor.execute("INSERT INTO art_tag (art_id, tag_ID) VALUES (%(id)s, %(tag)s)", d)
self.db_cursor.execute("INSERT INTO art_to_tag (art_id, tag_ID) VALUES (%(id)s, %(tag)s)", d)
except psycopg2.Error as e:
if e.pgcode == UNIQUE_VIOLATION:
logging.debug(e)
@ -108,7 +109,7 @@ class DBAdapter:
if author in old_authors:
continue
d = {"id": ID, "author_name": author[0], "author_domain": author[1]}
self.db_cursor.execute("INSERT INTO art_author (presence_name, presence_domain, art_ID) " +
self.db_cursor.execute("INSERT INTO art_to_presence (presence_name, presence_domain, art_ID) " +
"VALUES (%(author_name)s, %(author_domain)s, %(id)s)", d)
for old_author_name, old_author_domain in old_authors:
if (old_author_name, old_author_domain) not in authors: # need to remove old author
@ -149,7 +150,7 @@ class DBAdapter:
:return:
"""
d = {"name": presence_name, "domain": presence_domain, "id": art_ID}
self.db_cursor.execute("DELETE FROM art_author " +
self.db_cursor.execute("DELETE FROM art_to_presence " +
"WHERE presence_name = %(name)s and " +
"presence_domain = %(domain)s and art_ID = %(id)s",
d)
@ -162,7 +163,7 @@ class DBAdapter:
:return:
"""
d = {"id": art_ID, "tag": tag_ID}
self.db_cursor.execute("DELETE FROM art_tag WHERE art_id = %(id)s and tag_id = %(tag)s", d)
self.db_cursor.execute("DELETE FROM art_to_tag WHERE art_id = %(id)s and tag_id = %(tag)s", d)
def save_presence(self, name: str, domain: str, artist_ID: int, link: str):
"""
@ -407,7 +408,7 @@ class DBAdapter:
return None
d = {"id": art_id}
self.db_cursor.execute("SELECT presence_name, presence_domain FROM art_author WHERE art_ID = %(id)s", d)
self.db_cursor.execute("SELECT presence_name, presence_domain FROM art_to_presence WHERE art_ID = %(id)s", d)
presences = self.db_cursor.fetchall()
result = []
@ -424,7 +425,7 @@ class DBAdapter:
"""
d = {"id": id}
self.db_cursor.execute("SELECT presence_name, presence_domain FROM art_author WHERE art_ID = %(id)s", d)
self.db_cursor.execute("SELECT presence_name, presence_domain FROM art_to_presence WHERE art_ID = %(id)s", d)
presences = self.db_cursor.fetchall()
result = []
@ -440,7 +441,7 @@ class DBAdapter:
:return:
"""
d = {"id": art_ID}
self.db_cursor.execute("SELECT tag_ID FROM art_tag WHERE art_id = %(id)s", d)
self.db_cursor.execute("SELECT tag_ID FROM art_to_tag WHERE art_id = %(id)s", d)
rows = self.db_cursor.fetchall()
new_rows = []

Loading…
Cancel
Save