[Collab-qa-commits] r983 - in udd/src: . udd

neronus-guest at alioth.debian.org neronus-guest at alioth.debian.org
Sun Aug 3 16:51:15 UTC 2008


Author: neronus-guest
Date: 2008-08-03 16:51:14 +0000 (Sun, 03 Aug 2008)
New Revision: 983

Modified:
   udd/src/db_manager.py
   udd/src/setup-db.sql
   udd/src/udd/bugs_gatherer.pl
Log:
Split bugs table into bugs_archived and bugs_unarchived
Created bugs VIEW as union of bugs_archived and bugs_unarchived


Modified: udd/src/db_manager.py
===================================================================
--- udd/src/db_manager.py	2008-08-03 13:10:16 UTC (rev 982)
+++ udd/src/db_manager.py	2008-08-03 16:51:14 UTC (rev 983)
@@ -6,9 +6,10 @@
 
 """This scripts sets up and deletes the tables of the database"""
 
-TABLES = ('sources', 'packages', 'popcon', 'migrations', 'bugs', 'bug_merged_with', 'bug_user_tags', 'bug_found_in',
-          'bug_fixed_in', 'upload_history')
-VIEWS = ('popcon_src_average', 'popcon_src_max')
+TABLES = ('sources', 'packages', 'popcon', 'migrations', 'bugs_archived',
+    'bugs_unarchived', 'bug_merged_with', 'bug_user_tags', 'bug_found_in',
+    'bug_fixed_in', 'bug_tags', 'upload_history')
+VIEWS = ('popcon_src_average', 'popcon_src_max', 'bugs')
 
 def print_help():
   print "Usage: %s <config> <delete|setup>" % sys.argv[0]

Modified: udd/src/setup-db.sql
===================================================================
--- udd/src/setup-db.sql	2008-08-03 13:10:16 UTC (rev 982)
+++ udd/src/setup-db.sql	2008-08-03 16:51:14 UTC (rev 983)
@@ -25,13 +25,18 @@
    distribution text,
    PRIMARY KEY (package, distribution));
 
-CREATE TABLE bugs
+CREATE TABLE bugs_unarchived
   (id int PRIMARY KEY, package text, source text, arrival timestamp, status text,
-     severity text, tags text, submitter text, owner text, title text,
+     severity text, submitter text, owner text, title text,
      last_modified timestamp, affects_stable boolean,
-    affects_testing boolean, affects_unstable boolean,
-is_archived boolean);
+    affects_testing boolean, affects_unstable boolean);
 
+CREATE TABLE bugs_archived
+  (id int PRIMARY KEY, package text, source text, arrival timestamp, status text,
+     severity text, submitter text, owner text, title text,
+     last_modified timestamp, affects_stable boolean,
+    affects_testing boolean, affects_unstable boolean);
+
 CREATE TABLE bug_merged_with
   (id int, merged_with int,
 PRIMARY KEY(id, merged_with));
@@ -47,6 +52,19 @@
   (id int, version text,
    PRIMARY KEY(id, version));
 
+CREATE TABLE bug_tags
+  (id int, tag text, PRIMARY KEY (id, tag));
+
+CREATE VIEW bugs AS
+  SELECT id, package, source, arrival, status, severity, submitter, owner,
+        title, last_modified, affects_stable, affects_testing,
+	affects_unstable, TRUE as is_archived
+  FROM bugs_archived
+  UNION
+  SELECT id, package, source, arrival, status, severity, submitter, owner,
+	title, last_modified, affects_stable, affects_testing,
+	affects_unstable, FALSE as is_archived FROM bugs_unarchived;
+
 CREATE TABLE upload_history
  (package text, version text, date timestamp with time zone, changed_by text,
   maintainer text, nmu boolean, signed_by text, key_id text);
@@ -80,6 +98,8 @@
 GRANT SELECT ON popcon_src_average TO PUBLIC;
 GRANT SELECT ON popcon_src_max TO PUBLIC;
 GRANT SELECT ON bugs TO PUBLIC;
+GRANT SELECT ON bugs_archived TO PUBLIC;
+GRANT SELECt ON bugs_unarchived TO PUBLIC;
 GRANT SELECT ON bug_merged_with TO PUBLIC;
 GRANT SELECT ON bug_found_in TO PUBLIC;
 GRANT SELECT ON bug_fixed_in TO PUBLIC;

Modified: udd/src/udd/bugs_gatherer.pl
===================================================================
--- udd/src/udd/bugs_gatherer.pl	2008-08-03 13:10:16 UTC (rev 982)
+++ udd/src/udd/bugs_gatherer.pl	2008-08-03 16:51:14 UTC (rev 983)
@@ -1,5 +1,5 @@
 #!/usr/bin/perl
-# Last-Modified: <Sun Aug  3 13:11:34 2008>
+# Last-Modified: <Sun Aug  3 16:19:54 2008>
 
 use strict;
 use warnings;
@@ -152,8 +152,8 @@
 	# Delete all bugs we are going to import
 	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};
+			$dbh->prepare("DELETE FROM $_ WHERE id = $bug")->execute() or die $!
+		} qw{bugs_archived bugs_unarchived bug_merged_with bug_found_in bug_fixed_in bug_tags};
 	}
 	print "Bugs deleted\n";
 
@@ -162,9 +162,10 @@
 
 	# XXX What if a bug is in location 'db' (which currently doesn't exist)
 	my $location = $src_config{archived} ? 'archive' : 'db_h';
+	my $table = $src_config{archived} ? 'bugs_archived' : 'bugs_unarchived';
 	# Read all bugs
 	foreach my $bug_nr (@modified_bugs) {
-		#next unless $bug_nr =~ /00$/;
+		next unless $bug_nr =~ /00$/;
 		# Fetch bug using Debbugs
 		# Bugs which were once archived and have been unarchived again will appear in get_bugs(archive => 1).
 		# However, those bugs are not to be found in location 'archive', so we detect them, and skip them
@@ -176,6 +177,7 @@
 		map { $bug{$_} = $dbh->quote($bug{$_}) } qw(subject originator owner pending);
 		my @found_versions = map { $dbh->quote($_) } @{$bug{found_versions}};
 		my @fixed_versions = map { $dbh->quote($_) } @{$bug{fixed_versions}};
+		my @tags = map {$dbh->quote($_) } split / /, $bug{keywords};
 
 		# log_modified and date are not necessarily set. If they are not available, they
 		# are assumed to be epoch (i.e. bug #4170)
@@ -230,10 +232,10 @@
 
 
 		# Insert data into bugs table
-		my $query = "INSERT INTO bugs VALUES ($bug_nr, '$bug{package}', $source, $bug{date}, \
-		             E$bug{pending}, '$bug{severity}', '$bug{keywords}', E$bug{originator}, E$bug{owner}, \
+		my $query = "INSERT INTO $table VALUES ($bug_nr, '$bug{package}', $source, $bug{date}, \
+		             E$bug{pending}, '$bug{severity}', E$bug{originator}, E$bug{owner}, \
 					 E$bug{subject}, $bug{log_modified}, $present_in_stable,
-					 $present_in_testing, $present_in_unstable, " . ($src_config{archived} ? 'True' : 'False') . ")";
+					 $present_in_testing, $present_in_unstable)";
 		# Execute insertion
 		my $sth = $dbh->prepare($query);
 		$sth->execute() or die $!;
@@ -251,6 +253,10 @@
 			$query = "INSERT INTO bug_merged_with VALUES ($bug_nr, $mergee)";
 			$dbh->prepare($query)->execute() or die $!;
 		}
+		foreach my $tag (without_duplicates(@tags)) {
+			$query = "INSERT INTO bug_tags VALUES ($bug_nr, $tag)";
+			$dbh->prepare($query)->execute() or die $!;
+		}
 	}
 
 	$dbh->commit();




More information about the Collab-qa-commits mailing list