ensembl-hive  2.8.1
create_sql_patches.pl
Go to the documentation of this file.
1 #!/usr/bin/env perl
2 # See the NOTICE file distributed with this work for additional information
3 # regarding copyright ownership.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 use strict;
18 use warnings;
19 
20  # Finding out own path in order to reference own components (including own modules):
21 use Cwd ();
22 use File::Basename ();
23 BEGIN {
24  $ENV{'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( Cwd::realpath($0) ) );
25  unshift @INC, $ENV{'EHIVE_ROOT_DIR'}.'/modules';
26 }
27 
28 use DateTime;
29 use File::Basename;
30 use File::Copy;
31 use Getopt::Long qw(:config no_auto_abbrev);
32 
34 
35 my $opts = {
36  driver => [],
37  date => undef, # this means today
38  help => 0,
39 };
40 my @args = ('driver=s@', 'date=s', 'help|h');
41 
42 my $parse = GetOptions($opts, @args);
43 if(!$parse) {
44  print STDERR "Could not parse the given arguments. Please consult the help\n";
45  usage();
46  exit 1;
47 }
48 
49 # Print usage on '-h' command line option
50 if ($opts->{help}) {
51  usage();
52  exit;
53 }
54 
55 $opts->{driver} = [qw(mysql sqlite pgsql)] unless scalar(@{$opts->{driver}});
56 $opts->{date} = DateTime->now->ymd('-') unless $opts->{date};
57 
59  || die "Could not establish code_sql_schema_version, please check that 'EHIVE_ROOT_DIR' environment variable is set correctly\n";
60 
61 foreach my $driver (@{$opts->{driver}}) {
62  -s "$ENV{'EHIVE_ROOT_DIR'}/sql/patch_$opts->{date}.$driver" && die "$ENV{'EHIVE_ROOT_DIR'}/sql/patch_$opts->{date}.$driver already exists ! Remove this file or change the patch date\n";
63  system("sed 's/___EXPECTED_SCHEMA_VERSION___/$code_sql_schema_version/' '$ENV{'EHIVE_ROOT_DIR'}/sql/template_patch.$driver' > '$ENV{'EHIVE_ROOT_DIR'}/sql/patch_$opts->{date}.$driver'");
64  -s "$ENV{'EHIVE_ROOT_DIR'}/sql/patch_$opts->{date}.$driver" || die "Could not copy $ENV{'EHIVE_ROOT_DIR'}/sql/template_patch.$driver to $ENV{'EHIVE_ROOT_DIR'}/sql/patch_$opts->{date}.$driver\n";
65 }
66 
67 sub usage {
68  print <<EOT;
69 Usage:
70 \t$0 [-date <day_of_the_patch>] [-driver <name_of_first_driver>] [-driver <name_of_second_driver>] ...
71 \t$0 -h
72 
73 \t-date\n\t\tdate in ISO format, e.g. 2015-02-14. Defaults to the current date
74 \t-driver (can be repeated)\n\t\tdriver for which create a patch. Defaults to MySQL, SQLite, and Postgre
75 \t-h|--help\n\t\tdisplay this help text
76 
77 EOT
78 }
79 
Bio::EnsEMBL::Hive::DBSQL::SqlSchemaAdaptor::get_code_sql_schema_version
public get_code_sql_schema_version()
Bio::EnsEMBL::Hive::DBSQL::SqlSchemaAdaptor
Definition: SqlSchemaAdaptor.pm:17
BEGIN
public BEGIN()
usage
public usage()