Commit 3f470190 authored by Leo Gordon's avatar Leo Gordon
Browse files

Allow script-based schema patches that can use API in addition to pure SQL-based patches

parent 730a6026
......@@ -119,10 +119,12 @@ sub new {
|| die "DB($safe_url) sql_schema_version mismatch: the database's version is '$db_sql_schema_version' but the code is already '$code_sql_schema_version'.\n"
."Unfortunately we cannot patch the database; you may have to create a new database or agree to run older code\n";
my $patcher_command = "$ENV{'EHIVE_ROOT_DIR'}/scripts/db_cmd.pl -url $safe_url";
my $sql_patcher_command = "$ENV{'EHIVE_ROOT_DIR'}/scripts/db_cmd.pl -url $safe_url";
die "DB($safe_url) sql_schema_version mismatch: the database's version is '$db_sql_schema_version' but the code is already '$code_sql_schema_version'.\n"
."Please upgrade the database by applying the following patches:\n\n".join("\n", map { "\t$patcher_command < $_" } @$new_patches)."\n\nand try again.\n";
."Please upgrade the database by applying the following patches:\n\n"
.join("\n", map { ($_=~/\.\w*sql\w*$/) ? "\t$sql_patcher_command < $_" : "$_ -url $safe_url" } @$new_patches)
."\n\nand try again.\n";
} elsif($code_sql_schema_version < $db_sql_schema_version) {
......
......@@ -42,11 +42,13 @@ sub find_all_sql_schema_patches {
my %all_patches = ();
if(my $hive_root_dir = $ENV{'EHIVE_ROOT_DIR'} ) {
foreach my $patch_path ( split(/\n/, `ls -1 $hive_root_dir/sql/patch_20*.*sql*`) ) {
foreach my $patch_path ( split(/\n/, `ls -1 $hive_root_dir/sql/patch_20*.*`) ) {
my ($patch_name, $driver) = ($patch_path=~/^(.+)\.(\w+)$/);
$driver = 'mysql' if ($driver eq 'sql'); # for backwards compatibility
$driver = 'script' if ($driver!~/sql/);
$all_patches{$patch_name}{$driver} = $patch_path;
}
} # otherwise will sliently return an empty hash
......@@ -63,8 +65,10 @@ sub get_sql_schema_patches {
my @ordered_patches = ();
foreach my $patch_key ( (sort keys %$all_patches)[$after_version..$code_schema_version-1] ) {
if(my $patch_path = $all_patches->{$patch_key}{$driver}) {
push @ordered_patches, $patch_path;
if(my $sql_patch_path = $all_patches->{$patch_key}{$driver}) {
push @ordered_patches, $sql_patch_path;
} elsif(my $script_patch_path = $all_patches->{$patch_key}{'script'}) {
push @ordered_patches, $script_patch_path;
} else {
return;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment