## 2+ Databases to add to this group, with optional role information attached
## Returns: undef
## Example: bucardo add dbgroup nycservers nyc1:source nyc2:source lax1
- ## TODO: Wildcards?
## Grab our generic usage message
my $usage = usage('add_dbgroup');
$QUIET or print qq{Created database group "$name"\n};
}
- ## Everything else is databases to add to this group
+ ## Add all these databases to the group
for my $fulldb (@nouns) {
+
## Figure out the optional role
my ($db,$role) = extract_name_and_role($fulldb);
## 1+ Name of a database group
## Returns: undef
## Example: bucardo remove dbgroup sales
- ## TODO: --force argument needed
## Grab our generic usage message
my $usage = usage('remove_dbgroup');
$sth->execute($name);
};
if ($@) {
- if ($@ =~ /"sync_targetgroup_fk"/) {
- die qq{Cannot remove database group "$name": it is being used by one or more syncs\n};
+ if ($@ =~ /"sync_dbs_fk"/) {
+ if ($bcargs->{force}) {
+ $QUIET or warn qq{Dropping all syncs that reference the dbgroup "$name"\n};
+ $dbh->rollback();
+ $dbh->do('DELETE FROM bucardo.sync WHERE dbs = ' . $dbh->quote($name));
+ eval {
+ $sth->execute($name);
+ };
+ goto NEND if ! $@;
+ }
+ else {
+ die qq{Cannot remove database group "$name": it is being used by one or more syncs\n};
+ }
}
die qq{Could not delete database group "$name"\n$@\n};
}
-
+ NEND:
$QUIET or print qq{Removed database group "$name"\n};
}
use Data::Dumper;
use lib 't','.';
use DBD::Pg;
-use Test::More tests => 22;
+use Test::More tests => 24;
use vars qw/$t $res $command $dbhX $dbhA $dbhB/;
$res = $bct->ctl('bucardo remove dbgroup foobar1 foobar2');
like ($res, qr/Removed database group "foobar1".*Removed database group "foobar2"/s, $t);
+$t = 'Removal of dbgroup fails if used in a sync';
+$bct->ctl('bucardo add herd therd bucardo_test1');
+$bct->ctl('bucardo add dbgroup foobar3 A:source B');
+$bct->ctl('bucardo add sync mysync herd=therd dbs=foobar3');
+$res = $bct->ctl('bucardo remove dbgroup foobar3');
+chomp $res;
+is ($res, q/Cannot remove database group "foobar3": it is being used by one or more syncs/, $t);
+
+$t = 'Removal of dbgroup works if used in a sync and the --force argument used';
+$res = $bct->ctl('bucardo remove dbgroup foobar3 --force');
+like ($res, qr/Dropping all syncs that reference the dbgroup "foobar3".*Removed database group "foobar3"/s, $t);
+
## Update
$bct->ctl('bucardo add dbgroup foobar');