From a30091583bf0a87214e73b793ab25a9f07c842fc Mon Sep 17 00:00:00 2001 From: Greg Sabino Mullane Date: Wed, 30 Nov 2011 10:50:40 -0500 Subject: [PATCH] Better 'list tables' display, tweak the tests. --- bucardo | 23 ++++++++++++++--------- t/02-bctl-table.t | 48 +++++++++++++++++++++++------------------------ 2 files changed, 38 insertions(+), 33 deletions(-) diff --git a/bucardo b/bucardo index 8d9d29d1e..c8df06248 100755 --- a/bucardo +++ b/bucardo @@ -3640,7 +3640,7 @@ sub list_tables { } ## Figure out the length of each item for a pretty display - my ($maxid,$maxname,$maxdb) = (1,1,1); + my ($maxid,$maxname,$maxdb,$maxpk) = (1,1,1,1); for my $row (values %$TABLE) { my $id = $row->{id}; next if @nouns and ! exists $matchtable{$id}; @@ -3648,23 +3648,28 @@ sub list_tables { my $name = "$row->{schemaname}.$row->{tablename}"; $maxname = length $name if length $name > $maxname; $maxdb = length $row->{db} if length $row->{db} > $maxdb; + $row->{ppk} = $row->{pkey} ? "$row->{pkey} ($row->{pkeytype})" : 'none'; + $maxpk = length $row->{ppk} if length $row->{ppk} > $maxpk; } ## Now do the actual printing ## Sort by schemaname then tablename - for my $row (sort { - $a->{schemaname} cmp $b->{schemaname} - or - $a->{tablename} cmp $b->{tablename} - } values %$TABLE) { + for my $row (sort numbered_relations values %$TABLE) { next if @nouns and ! exists $matchtable{$row->{id}}; - printf '%-*s Table: %-*s Database: %-*s', + printf '%-*s Table: %-*s DB: %-*s PK: %-*s', 1+$maxid, "$row->{id}.", $maxname, "$row->{schemaname}.$row->{tablename}", - $maxdb, $row->{db}; + $maxdb, $row->{db}, + $maxpk, $row->{ppk}; if ($row->{sync}) { - printf ' Syncs: '; + printf ' Syncs: '; print join ',' => sort keys %{ $row->{sync} }; } + if (defined $row->{ping}) { + printf ' ping:%s', $row->{ping} ? 'true' : 'false'; + } + if ($row->{rebuild_index}) { + print ' rebuild_index:true'; + } print "\n"; $VERBOSE >= 2 and show_all_columns($row); diff --git a/t/02-bctl-table.t b/t/02-bctl-table.t index fa2211d5d..25d14aeac 100644 --- a/t/02-bctl-table.t +++ b/t/02-bctl-table.t @@ -131,20 +131,20 @@ is ($res, qq{$addtable_msg:\n public.bucardo_test10\n}, $t); $t = q{'bucardo list tables' returns expected result}; $res = $bct->ctl('bucardo list tables'); $expected = -q{Table: public.bucardo_test1 DB: A PK: id (int2) -Table: public.bucardo_test2 DB: A PK: id|data1 (int4|text) -Table: public.bucardo_test3 DB: A PK: id (int8) -Table: public.bucardo_test4 DB: A PK: id (text) -Table: public.bucardo_test5 DB: A PK: id space (date) -Table: public.bucardo_test6 DB: A PK: id (timestamp) -Table: public.bucardo_test7 DB: A PK: id (numeric) -Table: public.bucardo_test8 DB: A PK: id (bytea) -Table: public.bucardo_test9 DB: A PK: id (int_unsigned) -Table: public.bucardo_test10 DB: A PK: id (timestamptz) -Table: public.droptest DB: A PK: none -Table: tschema.bucardo_test3 DB: A PK: none +qr{\d+\.\s* Table: public.bucardo_test1 DB: A PK: id \(int2\)\s+ +\d+\.\s* Table: public.bucardo_test2 DB: A PK: id\|data1 \(int4\|text\) +\d+\.\s* Table: public.bucardo_test3 DB: A PK: id \(int8\)\s+ +\d+\.\s* Table: public.bucardo_test4 DB: A PK: id \(text\)\s+ +\d+\.\s* Table: public.bucardo_test5 DB: A PK: id space \(date\)\s+ +\d+\.\s* Table: public.bucardo_test6 DB: A PK: id \(timestamp\)\s+ +\d+\.\s* Table: public.bucardo_test7 DB: A PK: id \(numeric\)\s+ +\d+\.\s* Table: public.bucardo_test8 DB: A PK: id \(bytea\)\s+ +\d+\.\s* Table: public.bucardo_test9 DB: A PK: id \(int_unsigned\)\s+ +\d+\.\s* Table: public.bucardo_test10 DB: A PK: id \(timestamptz\)\s+ +\d+\.\s* Table: public.droptest DB: A PK: none\s+ +\d+\.\s* Table: tschema.bucardo_test3 DB: A PK: none\s+ }; -is ($res, $expected, $t); +like ($res, $expected, $t); ## Remove them all, then try adding in various combinations empty_goat_table(); @@ -159,12 +159,12 @@ is ($res, qq{$addtable_msg:\n public.bucardo_test4\n}, $t); $t = q{'bucardo list tables' returns expected result}; $res = $bct->ctl('bucardo list tables'); $expected = -q{Table: public.bucardo_test1 DB: A PK: id (int2) -Table: public.bucardo_test2 DB: A PK: id|data1 (int4|text) -Table: public.bucardo_test4 DB: A PK: id (text) ping:true -Table: public.bucardo_test9 DB: A PK: id (int_unsigned) +qr{\d+\.\s* Table: public.bucardo_test1 DB: A PK: id \(int2\)\s* +\d+\.\s* Table: public.bucardo_test2 DB: A PK: id\|data1 \(int4\|text\)\s* +\d+\.\s* Table: public.bucardo_test4 DB: A PK: id \(text\)\s* ping:true\s* +\d+\.\s* Table: public.bucardo_test9 DB: A PK: id \(int_unsigned\)\s* }; -is ($res, $expected, $t); +like ($res, $expected, $t); $t = q{Add table works when specifying the rebuild_index and ping options}; $res = $bct->ctl('bucardo add table bucardo_test5 ping=false rebuild_index=1'); @@ -173,13 +173,13 @@ is ($res, qq{$addtable_msg:\n public.bucardo_test5\n}, $t); $t = q{'bucardo list tables' returns expected result}; $res = $bct->ctl('bucardo list tables'); $expected = -q{Table: public.bucardo_test1 DB: A PK: id (int2) -Table: public.bucardo_test2 DB: A PK: id|data1 (int4|text) -Table: public.bucardo_test4 DB: A PK: id (text) ping:true -Table: public.bucardo_test5 DB: A PK: id space (date) ping:false rebuild_index:1 -Table: public.bucardo_test9 DB: A PK: id (int_unsigned) +qr{\d+\.\s* Table: public.bucardo_test1 DB: A PK: id \(int2\)\s* +\d+\.\s* Table: public.bucardo_test2 DB: A PK: id|data1 \(int4\|text\)\s* +\d+\.\s* Table: public.bucardo_test4 DB: A PK: id \(text\)\s* ping:true\s* +\d+\.\s* Table: public.bucardo_test5 DB: A PK: id space \(date\)\s* ping:false\s* rebuild_index:true\s* +\d+\.\s* Table: public.bucardo_test9 DB: A PK: id \(int_unsigned\)\s* }; -is ($res, $expected, $t); +like ($res, $expected, $t); empty_goat_table(); -- 2.39.5