head	1.1;
access;
symbols
	TIGRIS_1_1_0RC2:1.1.2.1
	TIGRIS_1_1_0RC1:1.1.2.1
	TIGRIS_1_1:1.1.2.1.0.2
	TIGRIS_1_0_8:1.1.2.1
	TIGRIS_1_0_8RC3:1.1.2.1
	TIGRIS_1_0_8RC2:1.1.2.1
	TIGRIS_1_0_8RC1:1.1.2.1
	TIGRIS_1_0_7:1.1.2.1
	TIGRIS_1_0_7RC3:1.1.2.1
	TIGRIS_1_0_7RC2:1.1.2.1
	TIGRIS_1_0_7RC1:1.1.2.1
	TIGRIS_1_0_6:1.1.2.1
	TIGRIS_1_0_6RC5:1.1.2.1
	TIGRIS_1_0_6RC4:1.1.2.1
	TIGRIS_1_0_6RC3:1.1.2.1
	TIGRIS_1_0_6RC2:1.1.2.1
	TIGRIS_1_0_6RC1:1.1.2.1
	TIGRIS_1_0_5:1.1.2.1
	TIGRIS_1_0_5RC6:1.1.2.1
	TIGRIS_1_0_5RC5:1.1.2.1
	TIGRIS_1_0_5RC4:1.1.2.1
	TIGRIS_1_0_5RC3:1.1.2.1
	TIGRIS_1_0_5RC2:1.1.2.1
	TIGRIS_1_0_5RC1:1.1.2.1
	TIGRIS_1_0_4:1.1.2.1
	TIGRIS_1_0:1.1.0.2;
locks; strict;
comment	@# @;


1.1
date	2001.04.26.05.06.43;	author kmaples;	state Exp;
branches
	1.1.2.1;
next	;

1.1.2.1
date	2001.05.02.19.54.31;	author kmaples;	state Exp;
branches;
next	;


desc
@@


1.1
log
@Simple script to count records in databases by table.
@
text
@#!/usr/bin/perl -w
# -*- Perl -*- script to take simple 'snapshots' of databases
#
# $Id: $

use DBI;
use strict;

use Getopt::Long;

BEGIN {
    unshift(@@INC, "$ENV{SANDBOX}/scripts");
}
use HelmDB;

unless(@@ARGV){
    print qq[
snapshot_db_counts.pl: get counts of records in databases.
Usage:
    
    snapshot_db_counts.pl {database1} ... {databaseN}
    snapshot_db_counts.pl --all  

Returns records in the form '{database}:{table}:{# of records}' 
];
    exit;   
}



my $all_dbs; 
my @@databases;

GetOptions(
    'all' => \$all_dbs,
);

# Get handle to database:
my $dbh = HelmDB::connect(
    'mysql', $ENV{DATABASE_ADMIN_USER}, $ENV{DATABASE_ADMIN_PASSWORD});

if($all_dbs){
    my @@refs = HelmDB::runQuery($dbh,'show databases');
    foreach(@@refs){
        push(@@databases, $_->[0]);
#       $_ = $_->[0]; 
#       print $_ . "\n";
    }
} else {
    @@databases = @@ARGV;
}

foreach(@@databases){
    my $current_db = $_;
    
    # Bail unless we can use the named database:
    unless(HelmDB::runSQL($dbh, "use $current_db")){
        warn "Unable to use $current_db: $!\n";
        next;   
    }
    
    my @@tablerefs = HelmDB::runQuery($dbh, 'show tables');
    foreach my $tref (@@tablerefs){
        my $table = $tref->[0];
        my $count = (HelmDB::runQuery($dbh, "select count(*) from $table"))[0]->[0];
        
        print "$current_db:$table:$count\n";    
    }
        
}

$dbh->disconnect();

@


1.1.2.1
log
@Modified migration scripts to change the bugs@@ user to issues@@; added a script
which attempts to reconcile existing helm accounts with older issuezilla
accounts upon upgrade from versions prior to 0.8.4; removed the sql statement
which attempted a brute-force transformation of user accounts in favor of
the aforementioned script; added data validation tools in helm/tests; added
the shared perl db library that these scripts use (HelmDB.pm) in previous
commit.
@
text
@d4 1
a4 1
# $Id: snapshot_db_counts.pl,v 1.1 2001/04/26 05:06:43 kmaples Exp $
@

