forked from importers/git-importer
Import the link information into an extra table
This commit is contained in:
parent
95412bc834
commit
e8094cbc68
23
lib/db.py
23
lib/db.py
@ -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,
|
||||||
@ -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
|
||||||
|
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user