[Collab-qa-commits] r1243 - in udd: sql udd
lucas at alioth.debian.org
lucas at alioth.debian.org
Mon Sep 8 09:18:55 UTC 2008
Author: lucas
Date: 2008-09-08 09:18:54 +0000 (Mon, 08 Sep 2008)
New Revision: 1243
Modified:
udd/sql/setup.sql
udd/udd/bugs_gatherer.pl
udd/udd/packages_gatherer.py
udd/udd/upload_history_gatherer.py
Log:
added foreign keys, adapted import scripts to allow to use them. DB udd on udd.debian.net was updated manually.
Modified: udd/sql/setup.sql
===================================================================
--- udd/sql/setup.sql 2008-09-08 09:17:22 UTC (rev 1242)
+++ udd/sql/setup.sql 2008-09-08 09:18:54 UTC (rev 1243)
@@ -14,6 +14,11 @@
CREATE INDEX sources_distrelcomp_idx on sources(distribution, release, component);
+CREATE TABLE packages_summary ( package text, version text, source text,
+source_version text, maintainer text, distribution text, release text,
+component text,
+PRIMARY KEY (package, version, distribution, release, component));
+
CREATE TABLE packages
(package text, version text, architecture text, maintainer text, description
text, source text, source_version text, essential text, depends text,
@@ -23,13 +28,9 @@
md5sum text, bugs text, priority text, tag text, task text, python_version text,
provides text, conflicts text, sha256 text, original_maintainer text,
distribution text, release text, component text,
- PRIMARY KEY (package, version, architecture, distribution, release, component));
+ PRIMARY KEY (package, version, architecture, distribution, release, component),
+ FOREIGN KEY (package, version, distribution, release, component) REFERENCES packages_summary DEFERRABLE);
-CREATE TABLE packages_summary ( package text, version text, source text,
-source_version text, maintainer text, distribution text, release text,
-component text,
-PRIMARY KEY (package, version, distribution, release, component));
-
GRANT SELECT ON packages TO PUBLIC;
GRANT SELECT ON packages_summary TO PUBLIC;
@@ -51,6 +52,11 @@
CREATE INDEX ubuntu_sources_distrelcomp_idx on ubuntu_sources(distribution, release, component);
+CREATE TABLE ubuntu_packages_summary ( package text, version text, source text,
+source_version text, maintainer text, distribution text, release text,
+component text,
+PRIMARY KEY (package, version, distribution, release, component));
+
CREATE TABLE ubuntu_packages
(package text, version text, architecture text, maintainer text, description
text, source text, source_version text, essential text, depends text,
@@ -60,13 +66,9 @@
md5sum text, bugs text, priority text, tag text, task text, python_version text,
provides text, conflicts text, sha256 text, original_maintainer text,
distribution text, release text, component text,
- PRIMARY KEY (package, version, architecture, distribution, release, component));
+ PRIMARY KEY (package, version, architecture, distribution, release, component),
+ FOREIGN KEY (package, version, distribution, release, component) REFERENCES ubuntu_packages_summary DEFERRABLE);
-CREATE TABLE ubuntu_packages_summary ( package text, version text, source text,
-source_version text, maintainer text, distribution text, release text,
-component text,
-PRIMARY KEY (package, version, distribution, release, component));
-
GRANT SELECT ON ubuntu_sources TO PUBLIC;
GRANT SELECT ON ubuntu_packages TO PUBLIC;
GRANT SELECT ON ubuntu_packages_summary TO PUBLIC;
@@ -84,7 +86,7 @@
affects_testing boolean, affects_unstable boolean);
CREATE TABLE bugs_merged_with
- (id int REFERENCES bugs, merged_with int,
+ (id int REFERENCES bugs, merged_with int REFERENCES bugs DEFERRABLE,
PRIMARY KEY(id, merged_with));
CREATE TABLE bugs_found_in
@@ -105,7 +107,7 @@
affects_testing boolean, affects_unsarchived_table boolean);
CREATE TABLE archived_bugs_merged_with
- (id int REFERENCES archived_bugs, merged_with int,
+ (id int REFERENCES archived_bugs, merged_with int REFERENCES archived_bugs DEFERRABLE,
PRIMARY KEY(id, merged_with));
CREATE TABLE archived_bugs_found_in
@@ -117,10 +119,12 @@
PRIMARY KEY(id, version));
CREATE TABLE archived_bugs_tags
- (id int, tag text, PRIMARY KEY (id, tag));
+ (id int REFERENCES archived_bugs, tag text, PRIMARY KEY (id, tag));
+-- usertags are either for archived or unarchived bugs, so we can't add a
+-- foreign key here.
CREATE TABLE bugs_usertags
- (email text, tag text, id int REFERENCES bugs);
+ (email text, tag text, id int);
CREATE VIEW bugs_rt_affects_stable AS
SELECT id, package, source FROM bugs
Modified: udd/udd/bugs_gatherer.pl
===================================================================
--- udd/udd/bugs_gatherer.pl 2008-09-08 09:17:22 UTC (rev 1242)
+++ udd/udd/bugs_gatherer.pl 2008-09-08 09:18:54 UTC (rev 1243)
@@ -127,35 +127,18 @@
our $timing;
print "Inserting usertags: ",(time() - $t),"s\n" if $timing;
$t = time();
- run_usertags($config, $source, $dbh);
my %src_config = %{$config->{$source}};
my $table = $src_config{table};
my $archived_table = $src_config{'archived-table'};
my @modified_bugs;
- ####### XXX EXPERIMENT
- ####### XXX What to do with bugs both archived and unarchived
- #my $max_last_modified = get_db_max_last_modified($dbh);
- #my @modified_bugs;
- #if($max_last_modified) {
- # @modified_bugs = @{get_modified_bugs($max_last_modified)};
- # Delete modified bugs
- # for my $bug (@modified_bugs) {
- # map {
- # $dbh->prepare("DELETE FROM $_ WHERE id = $bug")->execute()
- # } qw{bugs bug_merged_with bug_found_in bug_fixed_in};
- # }
- #} else {
- # @modified_bugs = get_bugs(archive => 'both');
- #}
- #@modified_bugs = without_duplicates(@modified_bugs);
+
if($src_config{archived}) {
@modified_bugs = get_bugs(archive => 1);
} else {
@modified_bugs = get_bugs();
}
-
my @modified_bugs2;
if ($src_config{debug}) {
foreach $b (@modified_bugs) {
@@ -168,7 +151,7 @@
$t = time();
foreach my $prefix ($table, $archived_table) {
- foreach my $postfix ('', qw{_merged_with _found_in _fixed_in _tags}) {
+ foreach my $postfix (qw{_merged_with _found_in _fixed_in _tags}, '') {
my $sth = $dbh->prepare("DELETE FROM $prefix$postfix WHERE id = \$1");
map {
$sth->execute($_) or die $!;
@@ -180,7 +163,7 @@
# Used to chache binary to source mappings
my %binarytosource = ();
- # XXX What if a bug is in location 'db' (which currently doesn't exist)
+ # XXX What if a bug is in location 'db' (which currently
my $location = $src_config{archived} ? 'archive' : 'db_h';
#my $table = $src_config{archived} ? 'bugs_archived' : 'bugs';
$table = $src_config{archived} ? $archived_table : $table;
@@ -286,6 +269,9 @@
$insert_bugs_tags_handle->execute($bug_nr, $tag) or die $!;
}
}
+
+ # Also import usertags
+ run_usertags($config, $source, $dbh);
}
sub main {
@@ -306,6 +292,7 @@
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname");
# We want to commit the transaction as a hole at the end
$dbh->{AutoCommit} = 0;
+ $dbh->do('SET CONSTRAINTS ALL DEFERRED');
if($command eq 'run') {
run($config, $source, $dbh);
Modified: udd/udd/packages_gatherer.py
===================================================================
--- udd/udd/packages_gatherer.py 2008-09-08 09:17:22 UTC (rev 1242)
+++ udd/udd/packages_gatherer.py 2008-09-08 09:18:54 UTC (rev 1243)
@@ -68,7 +68,7 @@
packages_gatherer.warned_about[k] += 1
return d
- def import_packages(self, sequence):
+ def import_packages(self, sequence, cur):
"""Import the packages from the sequence into the database-connection
conn.
@@ -76,7 +76,6 @@
it is called.The Format of the sequence is expected to be that of a
debian packages file."""
# The fields that are to be read. Other fields are ignored
- cur = self.connection.cursor()
for control in debian_bundle.deb822.Packages.iter_paragraphs(sequence):
# Check whether packages with architectue 'all' have already been
# imported
@@ -150,6 +149,8 @@
self._distr = src_cfg['distribution']
cur = self.cursor()
+ # defer constraints checking until the end of the transaction
+ cur.execute("SET CONSTRAINTS ALL DEFERRED")
# For every part and every architecture, import the packages into the DB
for comp in src_cfg['components']:
@@ -180,7 +181,7 @@
file.close()
tmp.seek(0)
aux.print_debug("Importing from " + path)
- self.import_packages(open(tmp.name))
+ self.import_packages(open(tmp.name), cur)
tmp.close()
except IOError, (e, message):
print "Could not read packages from %s: %s" % (path, message)
Modified: udd/udd/upload_history_gatherer.py
===================================================================
--- udd/udd/upload_history_gatherer.py 2008-09-08 09:17:22 UTC (rev 1242)
+++ udd/udd/upload_history_gatherer.py 2008-09-08 09:18:54 UTC (rev 1243)
@@ -29,9 +29,9 @@
cursor = self.cursor()
- cursor.execute("DELETE FROM " + self.my_config['table'])
cursor.execute("DELETE FROM " + self.my_config['table'] + '_architecture')
cursor.execute("DELETE FROM " + self.my_config['table'] + '_closes')
+ cursor.execute("DELETE FROM " + self.my_config['table'])
cursor.execute("PREPARE uh_insert AS INSERT INTO %s VALUES \
($1, $2, $3, $4, $5, $6, $7, $8, $9)" % self.my_config['table'])
More information about the Collab-qa-commits
mailing list