Store {make,check,opt}depends in the database

In addition to parsing and storing dependencies of packages, store
makedepends, checkdepends and optdepends. Every dependency (of any type)
is displayed on the package details page.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2014-04-17 19:49:26 +02:00
parent 32b5d46643
commit 73936002f7
5 changed files with 90 additions and 24 deletions

View file

@ -142,6 +142,29 @@ CREATE UNIQUE INDEX VoteUsersIDPackageID ON PackageVotes (UsersID, PackageBaseID
CREATE UNIQUE INDEX NotifyUserIDPkgID ON CommentNotify (UserID, PackageBaseID); CREATE UNIQUE INDEX NotifyUserIDPkgID ON CommentNotify (UserID, PackageBaseID);
---- ----
12. Create a new table to store package dependency types:
----
CREATE TABLE DependencyTypes (
ID TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
Name VARCHAR(32) NOT NULL DEFAULT '',
PRIMARY KEY (ID)
) ENGINE = InnoDB;
INSERT INTO DependencyTypes VALUES (1, 'depends');
INSERT INTO DependencyTypes VALUES (2, 'makedepends');
INSERT INTO DependencyTypes VALUES (3, 'checkdepends');
INSERT INTO DependencyTypes VALUES (4, 'optdepends');
----
13. Add a field to store the dependency type to the PackageDepends table:
----
ALTER TABLE PackageDepends ADD COLUMN DepTypeID TINYINT UNSIGNED NOT NULL;
UPDATE PackageDepends SET DepTypeID = 1;
ALTER TABLE PackageDepends
ADD FOREIGN KEY (DepTypeID) REFERENCES DependencyTypes(ID) ON DELETE NO ACTION;
----
From 2.2.0 to 2.3.0 From 2.2.0 to 2.3.0
------------------- -------------------

View file

@ -133,15 +133,30 @@ CREATE TABLE Packages (
) ENGINE = InnoDB; ) ENGINE = InnoDB;
-- Define the package dependency types
--
CREATE TABLE DependencyTypes (
ID TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
Name VARCHAR(32) NOT NULL DEFAULT '',
PRIMARY KEY (ID)
) ENGINE = InnoDB;
INSERT INTO DependencyTypes VALUES (1, 'depends');
INSERT INTO DependencyTypes VALUES (2, 'makedepends');
INSERT INTO DependencyTypes VALUES (3, 'checkdepends');
INSERT INTO DependencyTypes VALUES (4, 'optdepends');
-- Track which dependencies a package has -- Track which dependencies a package has
-- --
CREATE TABLE PackageDepends ( CREATE TABLE PackageDepends (
PackageID INTEGER UNSIGNED NOT NULL, PackageID INTEGER UNSIGNED NOT NULL,
DepTypeID TINYINT UNSIGNED NOT NULL,
DepName VARCHAR(64) NOT NULL, DepName VARCHAR(64) NOT NULL,
DepCondition VARCHAR(20), DepCondition VARCHAR(20),
INDEX (PackageID), INDEX (PackageID),
INDEX (DepName), INDEX (DepName),
FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE,
FOREIGN KEY (DepTypeID) REFERENCES DependencyTypes(ID) ON DELETE NO ACTION
) ENGINE = InnoDB; ) ENGINE = InnoDB;

View file

@ -28,7 +28,7 @@ MAX_USERS = 300 # how many users to 'register'
MAX_DEVS = .1 # what percentage of MAX_USERS are Developers MAX_DEVS = .1 # what percentage of MAX_USERS are Developers
MAX_TUS = .2 # what percentage of MAX_USERS are Trusted Users MAX_TUS = .2 # what percentage of MAX_USERS are Trusted Users
MAX_PKGS = 900 # how many packages to load MAX_PKGS = 900 # how many packages to load
PKG_DEPS = (1, 5) # min/max depends a package has PKG_DEPS = (1, 15) # min/max depends a package has
PKG_SRC = (1, 3) # min/max sources a package has PKG_SRC = (1, 3) # min/max sources a package has
PKG_CMNTS = (1, 5) # min/max number of comments a package has PKG_CMNTS = (1, 5) # min/max number of comments a package has
CATEGORIES_COUNT = 17 # the number of categories from aur-schema CATEGORIES_COUNT = 17 # the number of categories from aur-schema
@ -258,8 +258,11 @@ for p in list(seen_pkgs.keys()):
while i != num_deps: while i != num_deps:
dep = random.choice([k for k in seen_pkgs]) dep = random.choice([k for k in seen_pkgs])
if dep not in this_deps: if dep not in this_deps:
s = "INSERT INTO PackageDepends VALUES (%d, '%s', NULL);\n" deptype = random.randrange(1, 5)
s = s % (seen_pkgs[p], dep) if deptype == 4:
dep += ": for " + random.choice([k for k in seen_pkgs])
s = "INSERT INTO PackageDepends VALUES (%d, %d, '%s', NULL);\n"
s = s % (seen_pkgs[p], deptype, dep)
out.write(s) out.write(s)
i += 1 i += 1

View file

@ -150,7 +150,13 @@ if ($uid):
$pkginfo[] = array_merge($pkgbase_info, $section_info); $pkginfo[] = array_merge($pkgbase_info, $section_info);
} }
} }
$section_info = array('depends' => array(), 'source' => array()); $section_info = array(
'depends' => array(),
'makedepends' => array(),
'checkdepends' => array(),
'optdepends' => array(),
'source' => array()
);
/* Fall-through case. */ /* Fall-through case. */
case 'epoch': case 'epoch':
case 'pkgdesc': case 'pkgdesc':
@ -162,6 +168,9 @@ if ($uid):
break; break;
case 'source': case 'source':
case 'depends': case 'depends':
case 'makedepends':
case 'checkdepends':
case 'optdepends':
$section_info[$key][] = $value; $section_info[$key][] = $value;
break; break;
} }
@ -181,15 +190,12 @@ if ($uid):
if (!isset($pkgbase_info['pkgbase'])) { if (!isset($pkgbase_info['pkgbase'])) {
$pkgbase_info['pkgbase'] = $pkgbase_info['pkgname']; $pkgbase_info['pkgbase'] = $pkgbase_info['pkgname'];
} }
if (empty($pkgbase_info['depends'])) { foreach (array('source', 'depends', 'makedepends', 'checkdepends', 'optdepends') as $array_opt) {
$pkgbase_info['depends'] = array(); if (empty($pkgbase_info[$array_opt])) {
$pkgbase_info[$array_opt] = array();
} else { } else {
$pkgbase_info['depends'] = explode(" ", $pkgbase_info['depends']); $pkgbase_info[$array_opt] = explode(" ", $pkgbase_info[$array_opt]);
} }
if (empty($pkgbase_info['source'])) {
$pkgbase_info['source'] = array();
} else {
$pkgbase_info['source'] = explode(" ", $pkgbase_info['source']);
} }
$pkginfo[] = $pkgbase_info; $pkginfo[] = $pkgbase_info;
} }
@ -345,10 +351,12 @@ if ($uid):
foreach ($pkginfo as $pi) { foreach ($pkginfo as $pi) {
$pkgid = pkg_create($base_id, $pi['pkgname'], $pi['license'], $pi['full-version'], $pi['pkgdesc'], $pi['url']); $pkgid = pkg_create($base_id, $pi['pkgname'], $pi['license'], $pi['full-version'], $pi['pkgdesc'], $pi['url']);
foreach ($pi['depends'] as $dep) { foreach (array('depends', 'makedepends', 'checkdepends', 'optdepends') as $deptype) {
foreach ($pi[$deptype] as $dep) {
$deppkgname = preg_replace("/(<|=|>).*/", "", $dep); $deppkgname = preg_replace("/(<|=|>).*/", "", $dep);
$depcondition = str_replace($deppkgname, "", $dep); $depcondition = str_replace($deppkgname, "", $dep);
pkg_add_dep($pkgid, $deppkgname, $depcondition); pkg_add_dep($pkgid, $deptype, $deppkgname, $depcondition);
}
} }
foreach ($pi['source'] as $src) { foreach ($pi['source'] as $src) {

View file

@ -131,6 +131,21 @@ function pkg_dependencies($pkgid) {
return $deps; return $deps;
} }
/**
* Get the ID of a dependency type given its name
*
* @param string $name The name of the dependency type
*
* @return int The ID of the dependency type
*/
function pkg_dependency_type_id_from_name($name) {
$dbh = DB::connect();
$q = "SELECT ID FROM DependencyTypes WHERE Name = ";
$q.= $dbh->quote($name);
$result = $dbh->query($q);
return $result->fetch(PDO::FETCH_COLUMN, 0);
}
/** /**
* Determine packages that depend on a package * Determine packages that depend on a package
* *
@ -653,18 +668,20 @@ function pkg_create($base_id, $pkgname, $license, $pkgver, $pkgdesc, $pkgurl) {
* Add a dependency for a specific package to the database * Add a dependency for a specific package to the database
* *
* @param int $pkgid The package ID to add the dependency for * @param int $pkgid The package ID to add the dependency for
* @param string $type The type of dependency to add
* @param string $depname The name of the dependency to add * @param string $depname The name of the dependency to add
* @param string $depcondition The type of dependency for the package * @param string $depcondition The type of dependency for the package
* *
* @return void * @return void
*/ */
function pkg_add_dep($pkgid, $depname, $depcondition) { function pkg_add_dep($pkgid, $type, $depname, $depcondition) {
$dbh = DB::connect(); $dbh = DB::connect();
$q = sprintf("INSERT INTO PackageDepends (PackageID, DepName, DepCondition) VALUES (%d, %s, %s)", $q = sprintf("INSERT INTO PackageDepends (PackageID, DepTypeID, DepName, DepCondition) VALUES (%d, %d, %s, %s)",
$pkgid, $pkgid,
pkg_dependency_type_id_from_name($type),
$dbh->quote($depname), $dbh->quote($depname),
$dbh->quote($depcondition)); $dbh->quote($depcondition)
);
$dbh->exec($q); $dbh->exec($q);
} }