forked from importers/git-importer
Import the link information into an extra table
This commit is contained in:
parent
95412bc834
commit
e8094cbc68
25
lib/db.py
25
lib/db.py
@ -46,7 +46,8 @@ class DB:
|
||||
def create_tables(self):
|
||||
"""Create the tables if not existing - assumes connected"""
|
||||
|
||||
commands = (
|
||||
schemes = dict()
|
||||
schemes[1] = (
|
||||
"""
|
||||
CREATE TABLE scheme (
|
||||
id SERIAL PRIMARY KEY,
|
||||
@ -54,7 +55,7 @@ class DB:
|
||||
)
|
||||
""",
|
||||
"INSERT INTO scheme (version) VALUES(1)",
|
||||
""" DROP TABLE IF EXISTS revisions""",
|
||||
"""DROP TABLE IF EXISTS revisions """,
|
||||
""" CREATE TABLE revisions (
|
||||
id SERIAL PRIMARY KEY,
|
||||
project VARCHAR(255) NOT NULL,
|
||||
@ -71,12 +72,30 @@ class DB:
|
||||
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
|
||||
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
|
||||
|
@ -14,7 +14,11 @@ class DBRevision:
|
||||
) = row
|
||||
|
||||
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
|
||||
def import_obs_rev(cls, db, revision):
|
||||
@ -41,7 +45,7 @@ class DBRevision:
|
||||
cur = db.cursor()
|
||||
cur.execute(
|
||||
"SELECT * FROM revisions where project=%s and package=%s and rev=%s",
|
||||
(project, package, rev),
|
||||
(project, package, str(rev)),
|
||||
)
|
||||
row = cur.fetchone()
|
||||
cur.close()
|
||||
|
Loading…
Reference in New Issue
Block a user