2 # See the NOTICE file distributed with this work for additional information
3 # regarding copyright ownership.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
20 # Finding out own path in order to reference own components (including own modules):
22 use File::Basename ();
24 $ENV{
'EHIVE_ROOT_DIR'} ||= File::Basename::dirname( File::Basename::dirname( Cwd::realpath($0) ) );
25 unshift @INC, $ENV{
'EHIVE_ROOT_DIR'}.
'/modules';
31 use Getopt::Long qw(:config no_auto_abbrev);
37 date => undef, #
this means today
40 my @args = (
'driver=s@',
'date=s',
'help|h');
42 my $parse = GetOptions($opts, @args);
44 print STDERR
"Could not parse the given arguments. Please consult the help\n";
49 # Print usage on '-h' command line option
55 $opts->{driver} = [qw(mysql sqlite pgsql)] unless scalar(@{$opts->{driver}});
56 $opts->{date} = DateTime->now->ymd(
'-') unless $opts->{date};
59 || die
"Could not establish code_sql_schema_version, please check that 'EHIVE_ROOT_DIR' environment variable is set correctly\n";
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";
70 \t$0 [-date <day_of_the_patch>] [-driver <name_of_first_driver>] [-driver <name_of_second_driver>] ...
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