Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[ljcom] r9678: LJSUP-7287 (verify DB schema in moveuclu...

Committer: ailyin
LJSUP-7287 (verify DB schema in moveucluster)
U   trunk/bin/worker/moveucluster
U   trunk/cgi-bin/LJ/UserManage.pm
U   trunk/cgi-bin/LJ/Worker/UserManage/CheckTables.pm
Modified: trunk/bin/worker/moveucluster
===================================================================
--- trunk/bin/worker/moveucluster	2010-11-08 11:49:00 UTC (rev 9677)
+++ trunk/bin/worker/moveucluster	2010-11-09 03:56:59 UTC (rev 9678)
@@ -9,10 +9,34 @@
 
 package LJ::NewWorker::TheSchwartz::MoveUCluster;
 use base 'LJ::NewWorker::TheSchwartz';
+
+use Getopt::Long;
+
 sub capabilities {
     return LJ::UserManage->capabilities;
 }
 
+my $check_tables;
+
+sub options {
+    my ($self) = @_;
+    return (
+        'check-tables|c'  => \$check_tables,
+        $self->SUPER::options(),
+    );
+}
+
+sub work_as_script {
+    return unless $check_tables;
+
+    foreach my $clust (@LJ::CLUSTERS) {
+        warn "checking tables on cluster $clust...\n";
+        LJ::UserManage->check_tables($clust);
+    }
+
+    return 1;
+}
+
 __PACKAGE__->start;
 
 1;

Modified: trunk/cgi-bin/LJ/UserManage.pm
===================================================================
--- trunk/cgi-bin/LJ/UserManage.pm	2010-11-08 11:49:00 UTC (rev 9677)
+++ trunk/cgi-bin/LJ/UserManage.pm	2010-11-09 03:56:59 UTC (rev 9678)
@@ -366,5 +366,25 @@
         ? 'AND journalid NOT IN (' . join(', ', @protected_journals_ids) . ')' 
         : '';
 }
+
+sub check_tables {
+    my ($class, $clust) = @_;
+
+    my %table_info = (
+        LJ::UserManage::TABLES_INFO(),
+        LJ::UserManageInt::TABLES_INFO(),
+    );
+
+    my $dbh = LJ::get_cluster_master($clust); $dbh->{'RaiseError'} = 1;
+
+    my @tables = @{$dbh->selectcol_arrayref('SHOW TABLES')};
+    my @unspecified_tables = grep { !exists($table_info{$_}) } @tables;
+
+    if (@unspecified_tables) {
+        my $message = "I don't know how to deal with the following tables:\n" .
+            join("\n", map { "   $_" } @unspecified_tables) . "\n";
+        die $message;
+    }
+}
  
 1;

Modified: trunk/cgi-bin/LJ/Worker/UserManage/CheckTables.pm
===================================================================
--- trunk/cgi-bin/LJ/Worker/UserManage/CheckTables.pm	2010-11-08 11:49:00 UTC (rev 9677)
+++ trunk/cgi-bin/LJ/Worker/UserManage/CheckTables.pm	2010-11-09 03:56:59 UTC (rev 9678)
@@ -28,18 +28,8 @@
         return $class->finished($job, $callback);
     }
 
-    my $dbh = LJ::get_cluster_master($clust); $dbh->{'RaiseError'} = 1;
-
-    my @tables = @{$dbh->selectcol_arrayref('SHOW TABLES')};
-    my @unspecified_tables = grep { !exists($table_info{$_}) } @tables;
-
-    if (@unspecified_tables) {
-        my $message = "I don't know how to deal with the following tables:\n" .
-            join("\n", map { "   $_" } @unspecified_tables) . "\n";
-        die $message;
-    } else {
-        return $class->finished($job, $callback);
-    }
+    LJ::UserManage->check_tables($clust);
+    return $class->finished($job, $callback);
 }
 
 1;

Tags: andy, ljcom, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments