mirror of
https://gitlab.com/davical-project/davical.git
synced 2026-05-01 16:11:20 +00:00
Add options to not apply any patches.
This commit is contained in:
parent
eef603b509
commit
7120632632
@ -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,50 +50,54 @@ 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 ) {
|
||||||
printf( "Looking at patches[%d] (%s)\n", $i, $patches[$i]) if ( $debug );
|
$current_revision = get_current_revision();
|
||||||
if ( compare_revisions(revision_hash($patches[$i]),$current_revision) > 0 ) {
|
printf( "The database is currently at revision %d.%d.%d.\n", $current_revision->{'schema_major'}, $current_revision->{'schema_minor'}, $current_revision->{'schema_patch'} );
|
||||||
print "Applying patch $patches[$i] ... ";
|
|
||||||
if ( !apply_patch( $patches[$i] ) ) {
|
opendir( PATCHDIR, $patchdir ) or die "Can't open patch directory $patchdir";
|
||||||
# Skip to the end unless the next patch is an alternate for the same version.
|
my @patches = grep { /^([0-9]+)\.([0-9]+)\.([0-9]+)([a-z]?)\.sql$/ } readdir(PATCHDIR);
|
||||||
if ( defined($patches[$i+1]) && compare_revisions(revision_hash($patches[$i]),revision_hash($patches[$i+1])) == 0 ) {
|
closedir(PATCHDIR);
|
||||||
print "failed. Attempting next alternative.\n";
|
|
||||||
$applied--;
|
@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 );
|
||||||
|
if ( compare_revisions(revision_hash($patches[$i]),$current_revision) > 0 ) {
|
||||||
|
print "Applying patch $patches[$i] ... ";
|
||||||
|
if ( !apply_patch( $patches[$i] ) ) {
|
||||||
|
# Skip to the end unless the next patch is an alternate for the same version.
|
||||||
|
if ( defined($patches[$i+1]) && compare_revisions(revision_hash($patches[$i]),revision_hash($patches[$i+1])) == 0 ) {
|
||||||
|
print "failed. Attempting next alternative.\n";
|
||||||
|
$applied--;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print "failed!\n$last_results ==> No further patches will be attempted!\n";
|
||||||
|
last;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
print "failed!\n$last_results ==> No further patches will be attempted!\n";
|
print "succeeded.\n";
|
||||||
last;
|
|
||||||
}
|
}
|
||||||
|
$applied++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
print "succeeded.\n";
|
print "Patch $patches[$i] has already been applied.\n" if ( $debug );
|
||||||
}
|
}
|
||||||
$applied++;
|
}
|
||||||
|
|
||||||
|
if ( $applied ) {
|
||||||
|
print "Successfully applied $applied patches.\n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
print "Patch $patches[$i] has already been applied.\n" if ( $debug );
|
print "No patches were applied.\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $applied ) {
|
|
||||||
print "Successfully applied $applied patches.\n";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
print "No patches were applied.\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
# Ensure the locales data is up to date
|
# Ensure the locales data is up to date
|
||||||
apply_sql_file( $dbadir, "supported_locales.sql" );
|
apply_sql_file( $dbadir, "supported_locales.sql" );
|
||||||
print "Supported locales updated.\n";
|
print "Supported locales updated.\n";
|
||||||
@ -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);
|
||||||
|
|
||||||
@ -279,13 +289,15 @@ sub show_usage {
|
|||||||
update-rscds-database [options]
|
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user