]> git.donarmstrong.com Git - wannabuild.git/blobdiff - bin/wanna-build
Add support for the public view of the data.
[wannabuild.git] / bin / wanna-build
index 8401dff42a9b8d93bd25682eb1c20cb53c4b9424..070009fecb760a32822f775de4c1b34d76be5b5a 100755 (executable)
@@ -301,8 +301,18 @@ END {
        }
 }
 
-$dbh = DBI->connect("DBI:Pg:database=wanna-build") || 
-       die "FATAL: Cannot open database: $DBI::errstr\n";
+my $schema_suffix = '';
+# TODO: Base this on something else, like an option that is passed.
+if ($real_user eq 'nobody') {
+       $dbh = DBI->connect("DBI:Pg:service=wanna-build") || 
+               die "FATAL: Cannot open database: $DBI::errstr\n";
+       $schema_suffix = '_public';
+}
+else
+{
+       $dbh = DBI->connect("DBI:Pg:service=wanna-build-privileged") || 
+               die "FATAL: Cannot open database: $DBI::errstr\n";
+}
 
 # TODO: This shouldn't be needed, file a bug.
 $dbh->{pg_server_prepare} = 0;
@@ -1938,14 +1948,14 @@ sub check_entry {
                          join( "\n", map { "$_: $pkg->{$_}" } keys %$pkg ), "\n";
                die "Database entry lacks package or username field\n";
        }
-       if (!exists $pkg->{'version'}) {
-               die "Database entry for $pkg->{'package'} lacks Version: field\n";
-       }
        # if no State: field, generate one (for old db compat)
        if (!exists($pkg->{'state'})) {
                $pkg->{'state'} =
                        exists $pkg->{'failed'} ? 'Failed' : 'Building';
        }
+       if (!exists $pkg->{'version'} and $pkg->{'state'} ne 'Not-For-Us') {
+               die "Database entry for $pkg->{'package'} lacks Version: field\n";
+       }
        # check state field
        die "Bad state $pkg->{'state'} of package $pkg->{Package}\n"
                if !isin( $pkg->{'state'},
@@ -2374,11 +2384,11 @@ sub pkg_version_eq {
 }
 
 sub table_name {
-       return '"' . $arch . '".packages';
+       return '"' . $arch . $schema_suffix . '".packages';
 }
 
 sub user_table_name {
-       return '"' . $arch . '".users';
+       return '"' . $arch . $schema_suffix . '".users';
 }
 
 sub get_source_info {