Add options to not apply any patches.

This commit is contained in:
Andrew McMillan 2008-01-25 08:00:47 +13:00
parent eef603b509
commit 7120632632

View File

@ -19,6 +19,9 @@ my $dbpass = "";
my $dbhost = ""; my $dbhost = "";
my $appuser = "general"; my $appuser = "general";
my $helpmeplease = 0; my $helpmeplease = 0;
my $apply_patches = 1;
my $revoke_list = "general";
my $config_file = "";
my $dbadir = $0; my $dbadir = $0;
$dbadir =~ s#/[^/]*$##; $dbadir =~ s#/[^/]*$##;
@ -32,6 +35,9 @@ GetOptions ('debug!' => \$debug,
'dbport=s' => \$dbport, 'dbport=s' => \$dbport,
'dbhost=s' => \$dbhost, 'dbhost=s' => \$dbhost,
'appuser=s' => \$appuser, 'appuser=s' => \$appuser,
'patch!' => \$apply_patches,
'revoke=s' => \$revoke_list,
'config=s' => \$config_file,
'help' => \$helpmeplease ); 'help' => \$helpmeplease );
show_usage() if ( $helpmeplease ); show_usage() if ( $helpmeplease );
@ -44,19 +50,22 @@ my $dsn = "dbi:Pg:dbname=$dbname";
$dsn .= ";host=$dbhost" if ( "$dbhost" ne "" ); $dsn .= ";host=$dbhost" if ( "$dbhost" ne "" );
$dsn .= ";port=$dbport" if ( $dbport != 5432 ); $dsn .= ";port=$dbport" if ( $dbport != 5432 );
my $current_revision = get_current_revision(); my $current_revision;
printf( "The database is currently at revision %d.%d.%d.\n", $current_revision->{'schema_major'}, $current_revision->{'schema_minor'}, $current_revision->{'schema_patch'} );
opendir( PATCHDIR, $patchdir ) or die "Can't open patch directory $patchdir";
my @patches = grep { /^([0-9]+)\.([0-9]+)\.([0-9]+)([a-z]?)\.sql$/ } readdir(PATCHDIR);
closedir(PATCHDIR);
@patches = sort { compare_revisions(revision_hash($a),revision_hash($b), 1); } @patches;
my $applied = 0;
my $last_results = ''; # Will hold the last SQL result from applying a patch my $last_results = ''; # Will hold the last SQL result from applying a patch
for ( my $i=0; $i <= $#patches; $i++ ) { if ( $apply_patches ) {
$current_revision = get_current_revision();
printf( "The database is currently at revision %d.%d.%d.\n", $current_revision->{'schema_major'}, $current_revision->{'schema_minor'}, $current_revision->{'schema_patch'} );
opendir( PATCHDIR, $patchdir ) or die "Can't open patch directory $patchdir";
my @patches = grep { /^([0-9]+)\.([0-9]+)\.([0-9]+)([a-z]?)\.sql$/ } readdir(PATCHDIR);
closedir(PATCHDIR);
@patches = sort { compare_revisions(revision_hash($a),revision_hash($b), 1); } @patches;
my $applied = 0;
for ( my $i=0; $i <= $#patches; $i++ ) {
printf( "Looking at patches[%d] (%s)\n", $i, $patches[$i]) if ( $debug ); printf( "Looking at patches[%d] (%s)\n", $i, $patches[$i]) if ( $debug );
if ( compare_revisions(revision_hash($patches[$i]),$current_revision) > 0 ) { if ( compare_revisions(revision_hash($patches[$i]),$current_revision) > 0 ) {
print "Applying patch $patches[$i] ... "; print "Applying patch $patches[$i] ... ";
@ -79,13 +88,14 @@ for ( my $i=0; $i <= $#patches; $i++ ) {
else { else {
print "Patch $patches[$i] has already been applied.\n" if ( $debug ); print "Patch $patches[$i] has already been applied.\n" if ( $debug );
} }
} }
if ( $applied ) { if ( $applied ) {
print "Successfully applied $applied patches.\n"; print "Successfully applied $applied patches.\n";
} }
else { else {
print "No patches were applied.\n"; print "No patches were applied.\n";
}
} }
# Ensure the locales data is up to date # Ensure the locales data is up to date
@ -254,7 +264,7 @@ sub apply_permissions {
defined($current_grant) or die "No GRANT before ON in $permsfile\n"; defined($current_grant) or die "No GRANT before ON in $permsfile\n";
my $doohickeys = $1; my $doohickeys = $1;
$sql = sprintf( "REVOKE ALL ON %s FROM %s, general", $doohickeys, $appuser ); $sql = sprintf( "REVOKE ALL ON %s FROM %s, %s", $doohickeys, $appuser, $revoke_list );
print $sql, "\n" if ( $debug ); print $sql, "\n" if ( $debug );
$dbh->do($sql); $dbh->do($sql);
@ -280,12 +290,14 @@ update-rscds-database [options]
Options are: Options are:
--debug Turn on debugging --debug Turn on debugging
--dbname The database to dig into --dbname name The database to dig into
--dbuser Connect to the database as this user. --dbuser name Connect to the database as this user.
--dbport Connect to the database on this port. --dbport 5432 Connect to the database on this port.
--dbhost Connect to the database on this host. --dbhost name Connect to the database on this host.
--appuser The username which the application uses for it's database --appuser name The username which the application uses for it's database
connection. connection.
--nopatch Don't try and apply any patches
--revoke name Revoke permissions from this user
The program will apply any patches to the database which have The program will apply any patches to the database which have
not yet been applied, run any desired data patch scripts and set not yet been applied, run any desired data patch scripts and set