mvhub-dev team mailing list archive
-
mvhub-dev team
-
Mailing list archive
-
Message #00157
[Branch ~mvhub-commit/mvhub/trunk] Rev 377: merged fix_sql_tests
Merge authors:
Lee Goodrich (leegoodrich)
------------------------------------------------------------
revno: 377 [merge]
committer: Lee Goodrich <lgoodrich@xxxxxxxxxx>
branch nick: trunk
timestamp: Mon 2010-05-03 17:06:07 -0400
message:
merged fix_sql_tests
modified:
app-mvhub/conf/sql_select.lib
app-mvhub/setup/database/update_db.pl
--
lp:mvhub
https://code.launchpad.net/~mvhub-commit/mvhub/trunk
Your team MVHub Developers is subscribed to branch lp:mvhub.
To unsubscribe from this branch go to https://code.launchpad.net/~mvhub-commit/mvhub/trunk/+edit-subscription
=== modified file 'app-mvhub/conf/sql_select.lib'
--- app-mvhub/conf/sql_select.lib 2010-05-03 17:08:12 +0000
+++ app-mvhub/conf/sql_select.lib 2010-05-03 21:01:56 +0000
@@ -188,17 +188,6 @@
WHERE
category_id = ?
-[INFORMATION_SCHEMA_X_TABLE_EXISTS]
-SELECT
- 1
-FROM
- information_schema.tables
-WHERE
- table_name = ?
-AND
- schema = 'public'
-LIMIT 1
-
[PROGRAM_AGENCY_PROGRAM_CATEGORY_X_AGENCY_NAME_ID_PROGRAM_NAME]
SELECT
a.agency_name, p.program_id, p.program_name,
=== modified file 'app-mvhub/setup/database/update_db.pl'
--- app-mvhub/setup/database/update_db.pl 2010-05-03 17:19:03 +0000
+++ app-mvhub/setup/database/update_db.pl 2010-05-03 21:01:56 +0000
@@ -15,30 +15,30 @@
}
{ # main
- my $cfg_filename = $ENV{MV_CONFIG_FILE};
+ my $cfg_filename = $ENV{MV_CONFIG_FILE};
Getopt::Long::GetOptions( 'config=s' => \$cfg_filename )
- or die "GetOptions failed";
-
- my $dbh = MVHub::Utils::DB::get_dbh( $cfg_filename );
- my $cfg = MVHub::Utils::ConfigSimple::create_config_from( $cfg_filename );
-
- set_db_ENV_vars( $cfg );
-
- get_and_run_scripts( $dbh, $cfg);
+ or die "GetOptions failed";
+
+ my $dbh = MVHub::Utils::DB::get_dbh($cfg_filename);
+ my $cfg = MVHub::Utils::ConfigSimple::create_config_from($cfg_filename);
+
+ set_db_ENV_vars($cfg);
+
+ get_and_run_scripts( $dbh, $cfg );
}
sub get_and_run_scripts {
my ( $dbh, $cfg ) = @_;
-
- my $version = get_version( $dbh );
- my $path = $cfg->param("ABSOLUTE_PATH.setup_db_dir");
+
+ my $version = get_version($dbh);
+ my $path = $cfg->param("ABSOLUTE_PATH.setup_db_dir");
my @scripts = get_scripts( version => $version, path => $path );
-
- if ( !scalar @scripts ) {
+
+ if ( !scalar @scripts ) {
print "no scripts after version: $version found\n";
}
-
- run_scripts(@scripts);
+
+ run_scripts(@scripts);
}
sub set_db_ENV_vars {
@@ -55,59 +55,62 @@
sub get_version {
my $dbh = shift;
- my $version;
-
- my $exist_sql = "SELECT 1 FROM information_schema.tables WHERE table_name='version_log' LIMIT 1";
+ my $version;
+
+ my $exist_sql
+ = "SELECT 1 FROM information_schema.tables WHERE table_name='version_log' LIMIT 1";
my $table_exists = ( $dbh->selectrow_array($exist_sql) )[0];
- if ($table_exists) {
- my $sql = "SELECT max(version) FROM version_log;";
- $version = ( $dbh->selectrow_array($sql) )[0];
- }
- else {
- $version = 0;
- }
-
+ if ($table_exists) {
+ my $sql = "SELECT max(version) FROM version_log;";
+ $version = ( $dbh->selectrow_array($sql) )[0];
+ }
+ else {
+ $version = 0;
+ }
+
return $version;
}
sub get_scripts {
my %args = @_;
-
+
my @raw_scripts = glob "$args{path}/*.sql";
my @scripts;
- foreach my $script (sort @raw_scripts) {
-
- if ($script =~ m#\/(\d{3})_[\w\-]+\.sql#) {
- my $script_version = int $1;
-
- if ( $script_version > $args{'version'} ) {
- push @scripts, $script;
- }
- }
- else {
- die "ERROR: '$script' does not conform to naming standard: nnn_word_description.sql\n";
- }
+ foreach my $script ( sort @raw_scripts ) {
+
+ if ( $script =~ m#\/(\d{3})_[\w\-]+\.sql# ) {
+ my $script_version = int $1;
+
+ if ( $script_version > $args{'version'} ) {
+ push @scripts, $script;
+ }
+ }
+ else {
+ die
+ "ERROR: '$script' does not conform to naming standard: nnn_word_description.sql\n";
+ }
}
return sort @scripts;
}
sub run_scripts {
my @scripts = @_;
-
+
foreach my $script (@scripts) {
- my $filename = basename($script);
- print "Executing $filename...";
+ my $filename = basename($script);
+ print "Executing $filename...";
my $output = `psql -f $script 2>&1`;
- if ($output =~ /COMMIT/) {
- print "SUCCESS\n";
- }
- elsif ($output =~ /ROLLBACK/) {
- print "FAIL\n";
- print "The following OUTPUT occured while processing $filename:\n";
- die "$output\n\n****Processing $filename FAILED****\n";
- }
+ if ( $output =~ /COMMIT/ ) {
+ print "SUCCESS\n";
+ }
+ elsif ( $output =~ /ROLLBACK/ ) {
+ print "FAIL\n";
+ print
+ "The following OUTPUT occured while processing $filename:\n";
+ die "$output\n\n****Processing $filename FAILED****\n";
+ }
}
}