Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ensembl
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
ensembl
Commits
4580edb4
Commit
4580edb4
authored
18 years ago
by
Patrick Meidl
Browse files
Options
Downloads
Patches
Plain Diff
script to automagically apply schema patches to Ensembl dbs
parent
131eca8d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
misc-scripts/schema_patch.pl
+205
-0
205 additions, 0 deletions
misc-scripts/schema_patch.pl
with
205 additions
and
0 deletions
misc-scripts/schema_patch.pl
0 → 100755
+
205
−
0
View file @
4580edb4
#!/usr/local/bin/perl
=head1 NAME
schema_patch.pl - automagically apply schema patches to Ensembl dbs
=head1 SYNOPSIS
schema_patch.pl [arguments]
Required arguments:
--host, --dbhost, --db_host=HOST database host HOST
--port, --dbport, --db_port=PORT database port PORT
--user, --dbuser, --db_user=USER database username USER
--pass, --dbpass, --db_pass=PASS database passwort PASS
--pattern, --dbpattern=PATTERN patch databases where name matches PATTERN
--schema, --dbschema=NUM patch to schema version NUM
Optional arguments:
--conffile, --conf=FILE read parameters from FILE
(default: conf/Conversion.ini)
--bindir=DIR mysql binary directory (default:
/usr/local/ensembl/bin)
--logfile, --log=FILE log to FILE (default: *STDOUT)
--logpath=PATH write logfile to PATH (default: .)
--logappend, --log_append append to logfile (default: truncate)
-v, --verbose=0|1 verbose logging (default: false)
-i, --interactive=0|1 run script interactively (default: true)
-n, --dry_run, --dry=0|1 don't write results to database
-h, --help, -? print help (this message)
=head1 DESCRIPTION
This is a script to facilitate patching databases to the next schema version.
It will connect to a database server and apply schema patches to all databases
where the name matches a pattern. The pattern is a string that can be used in an
'IN' clause in SQL (e.g. "%_core_%"; if you want to patch only a single
database, use a pattern without % expansion, e.g. "homo_sapiens_core_38_36").
If you only want to check which patches need to be applied, use --dry_run=1
(best done in combination with --interactive=0).
=head1 LICENCE
This code is distributed under an Apache style licence:
Please see http://www.ensembl.org/code_licence.html for details
=head1 AUTHOR
Patrick Meidl <meidl@ebi.ac.uk>, Ensembl core API team
=head1 CONTACT
Please post comments/questions to the Ensembl development list
<ensembl-dev@ebi.ac.uk>
=cut
use
strict
;
use
warnings
;
no
warnings
'
uninitialized
';
use
FindBin
qw($Bin)
;
use
vars
qw($SERVERROOT)
;
BEGIN
{
$SERVERROOT
=
"
$Bin
/../..
";
unshift
(
@INC
,
"
$SERVERROOT
/ensembl/modules
");
}
use
Getopt::
Long
;
use
Pod::
Usage
;
use
Bio::EnsEMBL::Utils::
ConversionSupport
;
use
DBI
;
$|
=
1
;
my
$support
=
new
Bio::EnsEMBL::Utils::
ConversionSupport
(
$SERVERROOT
);
# parse options
$support
->
parse_common_options
(
@
_
);
$support
->
param
('
dbname
',
undef
);
$support
->
parse_extra_options
(
'
pattern|dbpattern=s
',
'
schema|dbschema=s
',
'
bindir=s
',
);
my
@params
=
map
{
$_
unless
(
$_
=~
/dbname/
)
}
$support
->
get_common_params
;
$support
->
allowed_params
(
@params
,
'
pattern
',
'
schema
',
'
bindir
',
);
if
(
$support
->
param
('
help
')
or
$support
->
error
)
{
warn
$support
->
error
if
$support
->
error
;
pod2usage
(
1
);
}
unless
(
$support
->
param
('
bindir
'))
{
$support
->
param
('
bindir
',
'
/usr/local/ensembl/bin
');
}
# ask user to confirm parameters to proceed
$support
->
confirm_params
;
# get log filehandle and print heading and parameters to logfile
$support
->
init_log
;
$support
->
check_required_params
(
'
pattern
',
'
schema
',
);
# connect to database
my
$dbh
=
$support
->
get_dbconnection
;
# read patches from file
$support
->
log
("
Reading patches from file...
\n
");
my
$patchdir
=
"
$SERVERROOT
/ensembl/sql
";
my
$schema
=
$support
->
param
('
schema
');
my
@patches
;
opendir
(
DIR
,
$patchdir
)
or
$support
->
log_error
("
Can't opendir
$SERVERROOT
/ensembl/sql: $!
");
while
(
my
$file
=
readdir
(
DIR
))
{
if
(
$file
=~
/^patch_\d+_${schema}.*\.sql/
)
{
$support
->
log
("
$file
\n
",
1
);
push
@patches
,
$file
;
}
}
$support
->
log
("
Done.
\n\n
");
# get all database names that match pattern
my
(
$sth
,
$sql
);
$sql
=
"
SHOW DATABASES LIKE '
"
.
$support
->
param
('
pattern
')
.
"
'
";
$sth
=
$dbh
->
prepare
(
$sql
);
$sth
->
execute
;
# loop over databases
while
(
my
(
$dbname
)
=
$sth
->
fetchrow_array
)
{
$support
->
log
("
$dbname
\n
");
if
(
$support
->
user_proceed
("
\n
Patch
$dbname
?
"))
{
# check which patches have already been applied
$sql
=
qq(SELECT meta_value FROM $dbname.meta WHERE meta_key = 'patch')
;
my
$sth1
=
$dbh
->
prepare
(
$sql
);
$sth1
->
execute
;
my
%applied
;
while
(
my
(
$val
)
=
$sth1
->
fetchrow_array
)
{
my
(
$file
)
=
split
(
/\|/
,
$val
);
$applied
{
$file
}
=
1
;
}
# apply the missing ones
foreach
my
$patch
(
sort
@patches
)
{
$support
->
log
("
$patch
...
",
1
);
if
(
$applied
{
$patch
})
{
$support
->
log
("
already applied.
\n
")
}
elsif
(
$support
->
param
('
dry_run
'))
{
$support
->
log
("
needs applying.
\n
")
}
else
{
$support
->
log
("
applying...
");
my
$cmd
=
$support
->
param
('
bindir
')
.
"
/mysql
"
.
"
-h
"
.
$support
->
param
('
host
')
.
"
-P
"
.
$support
->
param
('
port
')
.
"
-u
"
.
$support
->
param
('
user
')
.
"
-p
"
.
$support
->
param
('
pass
')
.
"
$dbname
<
$SERVERROOT
/ensembl/sql/
$patch
";
if
(
system
(
$cmd
)
==
0
)
{
$support
->
log
("
done.
\n
");
}
else
{
$support
->
log_warning
("
Error applying patch. Please check patch file.
\n
",
1
);
}
}
}
}
else
{
$support
->
log
("
Skipping on user's request.
\n
",
1
);
}
$support
->
log
("
Done.
\n\n
");
}
# finish logfile
$support
->
finish_log
;
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment