Update Tool
Upd to take in consideration the REPLACE user case.
This commit is contained in:
parent
3ad8b99ced
commit
09b0898e60
104
tools/update.pl
104
tools/update.pl
@ -11,19 +11,17 @@ use File::Copy;
|
|||||||
use DBI;
|
use DBI;
|
||||||
use DBD::mysql;
|
use DBD::mysql;
|
||||||
use YAML::XS;
|
use YAML::XS;
|
||||||
|
|
||||||
use lib "./"; #use current path for out lib as well
|
|
||||||
use rA_Common;
|
use rA_Common;
|
||||||
|
|
||||||
#prgm option
|
#prgm option
|
||||||
my $sHelp = 0;
|
my $sHelp = 0;
|
||||||
my $sValidTarget = "All|DB|Compile|Restart|Upd";
|
|
||||||
my $srABaseGitHttp = 'https://github.com/rathena/rathena.git';
|
my $srABaseGitHttp = 'https://github.com/rathena/rathena.git';
|
||||||
my $srABaseGitSSH = 'git@github.com:rathena/rathena.git';
|
my $srABaseGitSSH = 'git@github.com:rathena/rathena.git';
|
||||||
use constant {
|
use constant {
|
||||||
STATE_FILE => "SQL_Status.yml",
|
STATE_FILE => "SQL_Status.yml",
|
||||||
ST_OLD => "old",
|
ST_OLD => "old",
|
||||||
ST_SK => "skipped",
|
ST_SK => "skipped",
|
||||||
|
ST_DONE => "done",
|
||||||
SQL_HOST => "SQL_host",
|
SQL_HOST => "SQL_host",
|
||||||
SQL_PORT => "SQL_port",
|
SQL_PORT => "SQL_port",
|
||||||
SQL_UID => "SQL_userid",
|
SQL_UID => "SQL_userid",
|
||||||
@ -32,10 +30,11 @@ use constant {
|
|||||||
SQL_LOG_DB => ,"SQL_logdb"
|
SQL_LOG_DB => ,"SQL_logdb"
|
||||||
};
|
};
|
||||||
my %hFileState = ();
|
my %hFileState = ();
|
||||||
|
my $sValidTarget = "All|DB|Compile|Restart|Upd|MapDB";
|
||||||
|
|
||||||
#those following could be edited by user
|
#those following could be edited by user
|
||||||
my $sAutoDB = 0; #by default we ask for db setting
|
my $sAutoDB = 0; #by default we ask for db setting
|
||||||
my $sTarget = "Upd|DB|Compile"; #default target doesn't restart
|
my $sTarget = "Upd|DB|Compile|MapDB"; #default target doesn't restart
|
||||||
my %hDefConf = (
|
my %hDefConf = (
|
||||||
SQL_HOST => "localhost",
|
SQL_HOST => "localhost",
|
||||||
SQL_PORT => "3306",
|
SQL_PORT => "3306",
|
||||||
@ -45,7 +44,6 @@ my %hDefConf = (
|
|||||||
SQL_LOG_DB => ,"ragnarok",
|
SQL_LOG_DB => ,"ragnarok",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
GetArgs();
|
GetArgs();
|
||||||
Main();
|
Main();
|
||||||
|
|
||||||
@ -78,50 +76,85 @@ sub Main {
|
|||||||
if($sTarget =~ "All|Compile") { RunCompilation($sCurdir,$sTarget); }
|
if($sTarget =~ "All|Compile") { RunCompilation($sCurdir,$sTarget); }
|
||||||
}
|
}
|
||||||
|
|
||||||
sub UpdateSQL { my($sBaseDir,$sInit,$rhFileState) = @_;
|
sub GetSqlFileInDir { my($sDir) = @_;
|
||||||
#my @aMapDBFiles;
|
opendir (DIR, $sDir) or die $!;
|
||||||
my @aCharDBFiles; #for now we assum they all in same DB
|
|
||||||
#my @aLoginDBFiles;
|
|
||||||
my @aLogDBFiles;
|
|
||||||
|
|
||||||
chdir "sql-files/upgrades";
|
|
||||||
opendir (DIR, "./") or die $!;
|
|
||||||
my @aFiles
|
my @aFiles
|
||||||
= grep {
|
= grep {
|
||||||
/^(?!\.)/ # not begins with a period
|
/^(?!\.)/ # not begins with a period
|
||||||
&& /\.sql$/ # finish by .sql
|
&& /\.sql$/ # finish by .sql
|
||||||
&& -f "./$_" # and is a file
|
&& -f "$sDir/$_" # and is a file
|
||||||
} readdir(DIR);
|
} readdir(DIR);
|
||||||
|
closedir(DIR);
|
||||||
|
return \@aFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub UpdateSQL { my($sBaseDir,$sInit,$rhFileState) = @_;
|
||||||
|
my @aMapDBFiles = ();
|
||||||
|
my @aCharDBFiles = (); #for now we assum they all in same DB
|
||||||
|
my @aLoginDBFiles = ();
|
||||||
|
my @aLogDBFiles = ();
|
||||||
|
|
||||||
print "Preparing SQL folder\n" if($sInit==1);
|
print "Preparing SQL folder\n" if($sInit==1);
|
||||||
if(-e -r STATE_FILE) {
|
if(-e -r "sql-files/".STATE_FILE) {
|
||||||
print "Reading file status \n";
|
print "Reading file status \n";
|
||||||
$rhFileState = YAML::XS::LoadFile(STATE_FILE);
|
$rhFileState = YAML::XS::LoadFile("sql-files/".STATE_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach my $sFile (@aFiles){
|
if($sTarget =~ "All|MapDB") {
|
||||||
|
chdir "sql-files";
|
||||||
|
print "Getting Map SQL Db file \n";
|
||||||
|
my $raFilesMap = GetSqlFileInDir("./");
|
||||||
|
foreach my $sFile (@$raFilesMap){
|
||||||
|
if($sInit==1){
|
||||||
|
if(exists $$rhFileState{$sFile} && $$rhFileState{$sFile}{"status"} == ST_DONE ){
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
$$rhFileState{$sFile}{"status"} = ST_OLD;
|
||||||
|
$$rhFileState{$sFile}{"lastmod"} = (stat ($sFile))[9];
|
||||||
|
}
|
||||||
|
elsif($$rhFileState{$sFile}{"lastmod"} != (stat ($sFile))[9] ) {
|
||||||
|
print "The file $sFile was updated\n {\t ".$$rhFileState{$sFile}->{"lastmod"}." , ".(stat ($sFile))[9]."} \n";
|
||||||
|
push(@aMapDBFiles,$sFile);
|
||||||
|
$$rhFileState{$sFile}{"status"} = ST_DONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chdir "..";
|
||||||
|
}
|
||||||
|
|
||||||
|
chdir "sql-files/upgrades";
|
||||||
|
my $raFiles = GetSqlFileInDir("./");
|
||||||
|
|
||||||
|
foreach my $sFile (@$raFiles){
|
||||||
#print "Cur file = $sFile \n";
|
#print "Cur file = $sFile \n";
|
||||||
|
if($sInit==1){
|
||||||
next if(exists($rhFileState->{$sFile}) ); #either old or skipped
|
if(exists $$rhFileState{$sFile} && $$rhFileState{$sFile}{"status"} == ST_DONE ){
|
||||||
|
next;
|
||||||
if($sInit==1){ #move all file into old
|
|
||||||
if( $sFile =~ /_opt_/){
|
|
||||||
$$rhFileState{$sFile} = ST_SK;
|
|
||||||
next; # by default optional updated are put in skipped dir
|
|
||||||
}
|
}
|
||||||
$$rhFileState{$sFile} = ST_OLD;
|
|
||||||
|
if( $sFile =~ /_opt_/){
|
||||||
|
$$rhFileState{$sFile}{"status"} = ST_SK;
|
||||||
|
} else {
|
||||||
|
$$rhFileState{$sFile}{"status"} = ST_OLD;
|
||||||
|
}
|
||||||
|
$$rhFileState{$sFile}{"lastmod"} = (stat ($sFile))[9];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if(exists $$rhFileState{$sFile}){
|
||||||
|
my $sT = $$rhFileState{$sFile}{"status"};
|
||||||
|
my $sLastMode = $$rhFileState{$sFile}{"lastmod"};
|
||||||
|
# #if it's done or skipped don't do it, if it's old but updated do it
|
||||||
|
next if ( $sT eq ST_OLD or $sT eq ST_DONE or $sLastMode == (stat ($sFile))[9] );
|
||||||
|
}
|
||||||
|
|
||||||
if( $sFile =~ /_log.sql$/) {
|
if( $sFile =~ /_log.sql$/) {
|
||||||
print "Found log file = $sFile \n";
|
print "Found log file = $sFile \n";
|
||||||
push(@aLogDBFiles,$sFile);
|
push(@aLogDBFiles,$sFile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
print "Found file = $sFile \n";
|
print "Found char file = $sFile \n";\
|
||||||
push(@aCharDBFiles,$sFile);
|
push(@aCharDBFiles,$sFile);
|
||||||
}
|
}
|
||||||
|
$$rhFileState{$sFile}{"status"} = "done"; # the query will be applied so mark it so
|
||||||
|
|
||||||
# This part is for distributed DB, not supported yet
|
# This part is for distributed DB, not supported yet
|
||||||
# proposed nomenclature [lighta] : update_date_{opt_}(map|chr|acc|log).sql
|
# proposed nomenclature [lighta] : update_date_{opt_}(map|chr|acc|log).sql
|
||||||
@ -144,13 +177,10 @@ sub UpdateSQL { my($sBaseDir,$sInit,$rhFileState) = @_;
|
|||||||
# }
|
# }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($sInit==1){
|
if($sInit==0){ #apply update
|
||||||
print "Saving stateFile \n";
|
return;
|
||||||
YAML::XS::DumpFile(STATE_FILE,$rhFileState);
|
|
||||||
}
|
|
||||||
else{ #apply update
|
|
||||||
if( scalar(@aCharDBFiles)==0 and scalar(@aLogDBFiles)==0
|
if( scalar(@aCharDBFiles)==0 and scalar(@aLogDBFiles)==0
|
||||||
# and scalar(@aMapDBFiles)==0 and scalar(@aLoginDBFiles)==0
|
and scalar(@aMapDBFiles)==0 and scalar(@aLoginDBFiles)==0
|
||||||
){
|
){
|
||||||
print "No SQL Update to perform\n";
|
print "No SQL Update to perform\n";
|
||||||
}
|
}
|
||||||
@ -166,14 +196,18 @@ sub UpdateSQL { my($sBaseDir,$sInit,$rhFileState) = @_;
|
|||||||
$rhUserConf=\%hDefConf; #we assum it's set correctly
|
$rhUserConf=\%hDefConf; #we assum it's set correctly
|
||||||
}
|
}
|
||||||
|
|
||||||
#CheckAndLoadSQL(\@aMapDBFiles,$rhUserConf,$$rhUserConf{SQL_MAP_DB});
|
CheckAndLoadSQL(\@aMapDBFiles,$rhUserConf,$$rhUserConf{SQL_MAP_DB});
|
||||||
CheckAndLoadSQL(\@aCharDBFiles,$rhUserConf,$$rhUserConf{SQL_MAIN_DB});
|
CheckAndLoadSQL(\@aCharDBFiles,$rhUserConf,$$rhUserConf{SQL_MAIN_DB});
|
||||||
#CheckAndLoadSQL(\@aLoginDBFiles,$rhUserConf,$$rhUserConf{SQL_ACC_DB});
|
#CheckAndLoadSQL(\@aLoginDBFiles,$rhUserConf,$$rhUserConf{SQL_ACC_DB});
|
||||||
CheckAndLoadSQL(\@aLogDBFiles,$rhUserConf,$$rhUserConf{SQL_LOG_DB});
|
CheckAndLoadSQL(\@aLogDBFiles,$rhUserConf,$$rhUserConf{SQL_LOG_DB});
|
||||||
}
|
}
|
||||||
|
chdir "../..";
|
||||||
|
} else {
|
||||||
|
chdir "../..";
|
||||||
|
print "Saving stateFile \n";
|
||||||
|
YAML::XS::DumpFile("sql-files/".STATE_FILE,$rhFileState);
|
||||||
}
|
}
|
||||||
|
|
||||||
chdir "../..";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub RunCompilation { my($sBaseDir,$sTarget) = @_;
|
sub RunCompilation { my($sBaseDir,$sTarget) = @_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user