Import the link information into an extra table

This commit is contained in:
Stephan Kulow 2022-10-18 13:48:27 +02:00
parent 95412bc834
commit e8094cbc68
2 changed files with 31 additions and 8 deletions

View File

@ -46,7 +46,8 @@ class DB:
def create_tables(self): def create_tables(self):
"""Create the tables if not existing - assumes connected""" """Create the tables if not existing - assumes connected"""
commands = ( schemes = dict()
schemes[1] = (
""" """
CREATE TABLE scheme ( CREATE TABLE scheme (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
@ -54,7 +55,7 @@ class DB:
) )
""", """,
"INSERT INTO scheme (version) VALUES(1)", "INSERT INTO scheme (version) VALUES(1)",
""" DROP TABLE IF EXISTS revisions""", """DROP TABLE IF EXISTS revisions """,
""" CREATE TABLE revisions ( """ CREATE TABLE revisions (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
project VARCHAR(255) NOT NULL, project VARCHAR(255) NOT NULL,
@ -71,12 +72,30 @@ class DB:
CREATE UNIQUE INDEX ppr ON revisions (project, package, rev); CREATE UNIQUE INDEX ppr ON revisions (project, package, rev);
""", """,
) )
schemes[2] = (
"""DROP TABLE IF EXISTS links""",
"""
CREATE TABLE links (
id SERIAL PRIMARY KEY,
revision_id INTEGER,
project VARCHAR(255) NOT NULL,
package VARCHAR(255) NOT NULL
)
""",
"""
UPDATE scheme SET version=2
""",
)
if self.schema_version() > 0: schema_version = self.schema_version()
if (schema_version + 1) not in schemes:
return return
try: try:
cur = self.conn.cursor() cur = self.conn.cursor()
# create table one by one # create table one by one
for version, commands in schemes.items():
if version <= schema_version:
continue
for command in commands: for command in commands:
cur.execute(command) cur.execute(command)
# close communication with the PostgreSQL database server # close communication with the PostgreSQL database server

View File

@ -14,7 +14,11 @@ class DBRevision:
) = row ) = row
def links_to(self, db, project, package): def links_to(self, db, project, package):
pass db.cursor().execute(
"INSERT INTO links (revision_id, project, package) VALUES (%s,%s,%s)",
(self.dbid, project, package),
)
print("links_to", project, package)
@classmethod @classmethod
def import_obs_rev(cls, db, revision): def import_obs_rev(cls, db, revision):
@ -41,7 +45,7 @@ class DBRevision:
cur = db.cursor() cur = db.cursor()
cur.execute( cur.execute(
"SELECT * FROM revisions where project=%s and package=%s and rev=%s", "SELECT * FROM revisions where project=%s and package=%s and rev=%s",
(project, package, rev), (project, package, str(rev)),
) )
row = cur.fetchone() row = cur.fetchone()
cur.close() cur.close()