Rename "goat" to "relation".
authorDavid E. Wheeler <david@justatheory.com>
Sat, 27 Oct 2012 00:47:36 +0000 (17:47 -0700)
committerDavid E. Wheeler <david@justatheory.com>
Sat, 27 Oct 2012 00:47:36 +0000 (17:47 -0700)
All UI-based. Thanks to the separate table/sequence commands, there aren't too
many user-visible referenes to goats. The one place where it remains with
this commit (and the same goes for herd) is in the usage statement, which
references the `goat` table. I'd like to remove all references to tables
in usage statements altogether, but not in this commit. Resolves #24.

There was only one command that took a `goat` parameter: `add customcode`. It
was pretty seriously broken. It now mostly works, but the `relation` parameter
is ignored! This is because the customcode_map table needs an integer. So
should this be changed to "table"? And should it require the
$schema.$table_name format? Note the `XXX` added here. Ref GitHub #20.

Bucardo.pm
bucardo
bucardo.schema
t/20-postgres.t

index 62ea58870984762dd429862c56774dd0d552b8bf..50217900b1c597bea9ba8a36943385246783f7fb 100644 (file)
@@ -5739,7 +5739,7 @@ sub validate_sync {
 
             ## Save information about each column in the primary key
             if (!defined $g->{pkey} or !defined $g->{qpkey}) {
-                die "Table $g->{safetable} has no pkey or qpkey - do you need to run validate_goat on it?\n";
+                die "Table $g->{safetable} has no pkey or qpkey - do you need to run validate_goat() on it?\n";
             }
 
             ## Much of this is used later on, for speed of performing the sync
diff --git a/bucardo b/bucardo
index 0ac39cd47b114b0e6f9aef7b386dff4ce48bd974..2d22e5e3ea7908a361b56b999d62cf00c421beb5 100755 (executable)
--- a/bucardo
+++ b/bucardo
@@ -2533,7 +2533,6 @@ sub add_customname {
     my $item_name = shift @nouns || '';
 
     my $usage = usage('add_customname');
-
     ## Must have a second name as well
     my $newname = shift @nouns || '';
 
@@ -3313,7 +3312,7 @@ sub remove_table {
                 $sth->execute($name);
             };
             if ($@) {
-                die qq{Could not delete goat "$name"\n$@\n};
+                die qq{Could not delete relation "$name"\n$@\n};
             }
         }
         else {
@@ -3502,13 +3501,13 @@ sub update_table {
         if ($@) {
             $dbh->rollback();
             $dbh->disconnect();
-            print "Sorry, failed to update the bucardo.goat table. Error was:\n$@\n";
+            print "Sorry, failed to update the relation. Error was:\n$@\n";
             exit 1;
         }
 
         for my $item (sort keys %change) {
             my ($old,$new) = @{ $change{$item} };
-            print "Changed bucardo.goat $item from $old to $new\n";
+            print "Changed relation $item from $old to $new\n";
         }
 
         confirm_commit();
@@ -4642,7 +4641,7 @@ sub add_items_to_goat_table {
         $sth = $dbh->prepare($SQL);
         ($count = $sth->execute(@args)) =~ s/0E0/0/;
 
-        debug(qq{Added "$schema.$table" to goat table with db "$db", count was $count});
+        debug(qq{Added "$schema.$table" with db "$db", count was $count});
 
         push @newid => $sth->fetchall_arrayref()->[0][0];
     }
@@ -5764,7 +5763,7 @@ sub list_sequences {
     $count = $sth->execute();
     if ($count < 1) {
         $sth->finish();
-        printf "There are no%s entries in the 'goat' table.\n",
+        printf "There are no%s squences.\n",
             $WHERE ? ' matching' : '';
         return -1;
     }
@@ -5948,13 +5947,13 @@ sub add_customcode {
         getrows                  getrows              TF               null
         trigrules                trigrules            TF               null
         sync                     sync                 0                skip
-        goat                     goat                 0                skip
+        goat|relation            goat                 0                skip
         active                   active               TF               skip
         priority                 priority             number           skip
         src_code                 src_code             0                skip
     };
 
-    my ($dbcols,$cols,$phs,$vals)
+    my ($dbcols,$cols,$phs,$vals,$extras)
         = process_simple_args({cols => $validcols, list => \@nouns, usage => $usage});
 
     my $newname = $dbcols->{name};
@@ -5972,11 +5971,11 @@ sub add_customcode {
     }
 
     ## We must have a src_code as a file
-    if (! exists $dbcols->{src_code} or ! $dbcols->{src_code}) {
+    if (! exists $extras->{src_code} or ! $extras->{src_code}) {
         warn "$usage\n";
         exit 1;
     }
-    my $tfile = $dbcols->{src_code};
+    my $tfile = $extras->{src_code};
     if (! -e $tfile) {
         warn qq{Could not find a file named "$tfile"\n};
         exit 2;
@@ -5992,7 +5991,7 @@ sub add_customcode {
     $DEBUG and warn Dumper $vals;
     $sth = $dbh->prepare($SQL);
     eval {
-        $count = $sth->execute(@$vals, $src);
+        $count = $sth->execute((map { $vals->{$_} } sort keys %$vals), $src);
     };
     if ($@) {
         die "Failed to add customcode: $@\n";
@@ -6003,33 +6002,35 @@ sub add_customcode {
     ## See if any updates to customcode_map need to be made
 
     ## Only one of sync or goat can be specified
-    if ($dbcols->{sync} and $dbcols->{goat}) {
-        die qq{Sorry, you must specify a sync OR a goat, not both\n};
+    if ($extras->{sync} and $extras->{relation}) {
+        die qq{Sorry, you must specify a sync OR a relation, not both\n};
     }
 
     ## Makes no sense to specify priority or active if no goat or sync
-    if (($dbcols->{priority} or $dbcols->{active}) and !$dbcols->{sync} and ! $dbcols->{goat}) {
-        die qq{You must specify a sync or a goat when using priority or active\n};
+    if (($extras->{priority} or $extras->{active}) and !$extras->{sync} and ! $extras->{relation}) {
+        die qq{You must specify a sync or a relation when using priority or active\n};
     }
 
     ## Is this a valid sync?
-    if ($dbcols->{sync} and ! exists $global{sync}{$dbcols->{sync}}) {
+    if ($extras->{sync} and ! exists $global{sync}{$extras->{sync}}) {
         die qq{Unknown sync: $dbcols->{sync}\n};
     }
 
     ## Is this a valid gaot?
-    if ($dbcols->{goat} and ! exists $global{goat}{$dbcols->{goat}}) {
-        die qq{Unknown goat: $dbcols->{goat}\n};
+    if ($extras->{relation} and ! exists $global{goat}{$extras->{relation}}) {
+        die qq{Unknown relation: $extras->{relation}\n};
     }
 
     ## Add to the customcode_map table
-    if ($dbcols->{sync} or $dbcols->{goat}) {
+    if ($extras->{sync} or $extras->{relation}) {
         $SQL = 'INSERT INTO customcode_map(code,';
         my @vals;
-        for my $col (qw/sync goat priority active/) {
-            if ($dbcols->{$col}) {
+        # XXX Relation is text, but we need a goat.id. Should the param be
+        # table instead of relation, and should it look up the ID?
+        for my $col (qw/sync priority active/) {
+            if ($extras->{$col}) {
                 $SQL .= "$col,";
-                push @vals => $dbcols->{$col};
+                push @vals => $extras->{$col};
             }
         }
         my $phs2 = '?,' x @vals;
@@ -6260,7 +6261,7 @@ sub add_all_goats {
         my $tinfo;
         ## Do we already have this one?
         if (exists $hastable{$S}{$T}) {
-            $VERBOSE >= 2 and warn "Skipping $type already in goat: $S.$T\n";
+            $VERBOSE >= 2 and warn "Skipping $type already in relation: $S.$T\n";
             $count{seenit}++;
             $old{$S}{$T} = 1;
             if ($herd) {
@@ -6277,7 +6278,7 @@ sub add_all_goats {
             }
             next;
         }
-        $VERBOSE >= 2 and warn "Attempting to add $S.$T to the goat table\n";
+        $VERBOSE >= 2 and warn "Attempting to add relation $S.$T\n";
         eval {
             $count = $addtable->execute($db->{name},$S,$T,$type);
         };
@@ -6293,7 +6294,7 @@ sub add_all_goats {
         }
         if ($count != 1) {
             $addtable->finish();
-            warn "Failed to add $type $S.$T to the goat table!\n";
+            warn "Failed to add $type relation $S.$T!\n";
             $fail{$S}{$T} = 1;
             next;
         }
@@ -8890,7 +8891,7 @@ JOIN goat g ON (g.id = c.goat)
             $SEQUENCE->{$id} = $GOAT->{$id};
         }
         else {
-            die "Unknown goat type $type!";
+            die "Unknown relation type $type!";
         }
     }
 
@@ -9972,7 +9973,7 @@ execution of the custom code. Defaults to false.
 
 Name of the sync with which to associate the custom code.
 
-=item C<goat>
+=item C<relation>
 
 Name of the table or sequence with which to associate the custom code.
 
index 651ef158cbecc0ba2e24a1f20d6ae46a3ab4e59d..f5575881b8baf51bcf64b295e87b2866804067d9 100644 (file)
@@ -350,7 +350,7 @@ $bc$
     elog(DEBUG, "Running $SQL");
     my $count = spi_exec_query($SQL)->{processed};
     if ($count >= 1) {
-        elog(ERROR, "Cannot have goats from different databases in the same relgroup ($count)");
+        elog(ERROR, "Cannot have relations from different databases in the same relgroup ($count)");
     }
 
     ## Make sure that a herd contains at most one schemaname/tablename combination
@@ -366,7 +366,7 @@ $bc$
     elog(DEBUG, "Running $SQL");
     $count = spi_exec_query($SQL)->{rows}[0]{goats};
     if ($count >= 1) {
-        elog(ERROR, "Cannot have two goats with the same schema and table inside a relgroup (relgroup=$herdname) (goat=$new->{goat}) (count=$count)");
+        elog(ERROR, "Cannot have two relations with the same schema and table inside a relgroup (relgroup=$herdname) (relation=$new->{goat}) (count=$count)");
     }
 
     return;
index fb2d586906a1241ab1f813c7ce346717bffe4ecb..38879a3dcb9481b76913543cdfd3228c7b7a2272 100644 (file)
@@ -150,7 +150,7 @@ $t = q{Created a new sync for samedb};
 $res = $bct->ctl('bucardo add sync samedb relgroup=samerelgroup dbs=A,A1 status=inactive');
 like ($res, qr/Added sync "samedb"/, $t);
 
-## Create new relgroups, goats, and a sync
+## Create new relgroups, relations, and a sync
 $t = q{Created a new relgroup mrelgroup};
 $res = $bct->ctl('bucardo add relgroup mrelgroup mtest');
 like ($res, qr/Created relgroup "mrelgroup"/, $t);