diff --git a/scripts/dropdb.pl b/scripts/dropdb.pl index 578e1ef..1571d0f 100755 --- a/scripts/dropdb.pl +++ b/scripts/dropdb.pl @@ -46,17 +46,23 @@ my $dbh = DBI->connect( "DBI:MariaDB:host=$db_host;port=$db_port", or die 'Failed to connect to database: ' . $DBI::errstr; say 'Connected to database'; -say 'Existing databases:'; -my @db_names = - sort - map { s/DBI:MariaDB://r } - grep { !/information_schema|smchurla_ll/ } $dbh->data_sources(); -foreach (@db_names) { say " - $_"; } +while (1) { + say 'Existing databases:'; + my @db_names = + sort + map { s/DBI:MariaDB://r } + grep { !/information_schema|smchurla_ll/ } $dbh->data_sources(); + foreach (@db_names) { say " - $_"; } -print 'Enter name to delete: '; -my $db_sel = ; -chomp $db_sel; -$dbh->do("drop database `$db_sel`") - or die "Failed to drop database: " . $dbh->errstr; + print 'Enter single name or comma-separated list to delete: '; + my $db_sel = ; + chomp $db_sel; + my @selected_dbs = $db_sel eq "all" ? @db_names : split( ',', $db_sel ); + foreach (@selected_dbs) { + $dbh->do("drop database `$_`") + or die "Failed to drop database: " . $dbh->errstr; + + } +} $dbh->disconnect or warn $dbh->errstr;