75892bebe2505e10302cb56e9e1050bd811351d9
hiram
  Tue Sep 27 09:03:45 2022 -0700
accomodate promoted hubs with db but no chromInfo refs #29819

diff --git src/hg/utils/automation/HgAutomate.pm src/hg/utils/automation/HgAutomate.pm
index 7534b16..461722b 100755
--- src/hg/utils/automation/HgAutomate.pm
+++ src/hg/utils/automation/HgAutomate.pm
@@ -21,32 +21,32 @@
 # treated as constants) exported by this module:
 @EXPORT_OK = (
     # Support for common command line options:
     qw( getCommonOptionHelp processCommonOptions
 	@commonOptionVars @commonOptionSpec
       ),
     # Some basic smarts about our compute infrastructure:
     qw( choosePermanentStorage
 	chooseWorkhorse chooseFileServer
 	chooseClusterByBandwidth chooseSmallClusterByBandwidth
 	chooseFilesystemsForCluster checkClusterPath
       ),
     # General-purpose utility routines:
     qw( checkCleanSlate checkExistsUnlessDebug closeStdin
 	getAssemblyInfo getSpecies hubDateName gensub2 machineHasFile
-	databaseExists makeGsub mustMkdir asmHubBuildDir asmHubDownloadDir
-	mustOpen nfsNoodge paraRun run verbose
+	databaseExists dbTableExists makeGsub mustMkdir asmHubBuildDir
+	asmHubDownloadDir mustOpen nfsNoodge paraRun run verbose
       ),
     # Hardcoded paths/commands/constants:
     qw( $centralDbSql $git
 	$clusterData $trackBuild $goldenPath $images $gbdb
 	$splitThreshold $runSSH $setMachtype
       ),
 );
 
 #########################################################################
 # A simple model of our local compute environment with some subroutines
 # for checking the validity of path+machine combos and for suggesting
 # appropriate storage and machines.
 
 use vars qw( %cluster %clusterFilesystem $defaultDbHost );
 
@@ -793,30 +793,44 @@
   my $count = `$HgAutomate::runSSH $mach ls -1 $file 2>>/dev/null | wc -l`;
   chomp $count;
   return $count + 0;
 }
 
 sub databaseExists {
   my ($dbHost, $db) = @_;
   return 0 if ($dbHost =~ m/nohost/i);
   confess "Must have exactly 2 arguments" if (scalar(@_) != 2);
   my $query = "show databases like \"$db\";";
   my $line = `echo '$query' | $HgAutomate::runSSH $dbHost $centralDbSql`;
   chomp $line;
   return length($line);     # will be zero if not existing, >0 if exists
 }
 
+sub dbTableExists {
+  my ($dbHost, $db, $table) = @_;
+  return 0 if ($dbHost =~ m/nohost/i);
+  confess "Must have exactly 3 arguments" if (scalar(@_) != 3);
+  if (&HgAutomate::databaseExists($dbHost, $db)) {
+    my $query = "select count(*) from $db.$table;";
+    my $line = `echo '$query' | $HgAutomate::runSSH $dbHost $centralDbSql 2>>/dev/null`;
+    chomp $line;
+    return length($line);     # will be zero if not existing, >0 if exists
+  } else {	# no DB, no table
+    return 0;
+  }
+}
+
 sub makeGsub {
   # Create a gsub file in the given dir with the given contents.
   my ($runDir, $templateCmd) = @_;
   confess "Must have exactly 2 arguments" if (scalar(@_) != 2);
   confess "undef input" if (! defined $runDir || ! defined $templateCmd);
   chomp $templateCmd;
   my $fh = mustOpen(">$runDir/gsub");
   print $fh  <<_EOF_
 #LOOP
 $templateCmd
 #ENDLOOP
 _EOF_
     ;
   close($fh);
 }