ensembl-hive  2.6
SqlSchemaAdaptor.pm
Go to the documentation of this file.
1 =pod
2 
3 =head1 NAME
4 
6 
7 =head1 SYNOPSIS
8 
10 
11 =head1 DESCRIPTION
12 
13  This is currently an "objectless" adaptor for finding out the apparent code's SQL schema version
14 
15 =head1 LICENSE
16 
17  Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
18  Copyright [2016-2024] EMBL-European Bioinformatics Institute
19 
20  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
21  You may obtain a copy of the License at
22 
23  http://www.apache.org/licenses/LICENSE-2.0
24 
25  Unless required by applicable law or agreed to in writing, software distributed under the License
26  is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27  See the License for the specific language governing permissions and limitations under the License.
28 
29 =head1 CONTACT
30 
31  Please subscribe to the Hive mailing list: http://listserver.ebi.ac.uk/mailman/listinfo/ehive-users to discuss Hive-related questions or to be notified of our updates
32 
33 =cut
34 
35 
36 package Bio::EnsEMBL::Hive::DBSQL::SqlSchemaAdaptor;
37 
38 use strict;
39 use warnings;
40 
41 use File::Glob qw(bsd_glob);
42 
43 sub find_all_sql_schema_patches {
44 
45  my %all_patches = ();
46 
47  if(my $hive_root_dir = $ENV{'EHIVE_ROOT_DIR'} ) {
48  foreach my $patch_path ( glob "$hive_root_dir/sql/patch_20*.*" ) {
49  my ($patch_name, $driver) = ($patch_path=~/^(.+)\.(\w+)$/);
50 
51  $driver = 'mysql' if ($driver eq 'sql'); # for backwards compatibility
52 
53  $driver = 'script' if ($driver!~/sql/);
54 
55  $all_patches{$patch_name}{$driver} = $patch_path;
56  }
57  } # otherwise will sliently return an empty hash
58 
59  return \%all_patches;
60 }
61 
62 
63 sub get_sql_schema_patches {
64  my ($self, $after_version, $driver) = @_;
65 
66  my $all_patches = $self->find_all_sql_schema_patches();
67  my $code_schema_version = $self->get_code_sql_schema_version();
68 
69  my @ordered_patches = ();
70  foreach my $patch_key ( (sort keys %$all_patches)[$after_version..$code_schema_version-1] ) {
71  if(my $sql_patch_path = $all_patches->{$patch_key}{$driver}) {
72  push @ordered_patches, $sql_patch_path;
73  } elsif(my $script_patch_path = $all_patches->{$patch_key}{'script'}) {
74  push @ordered_patches, $script_patch_path;
75  } else {
76  return;
77  }
78  }
79 
80  return \@ordered_patches;
81 }
82 
83 
84 sub get_code_sql_schema_version {
85  my ($self) = @_;
86 
87  return scalar( keys %{ $self->find_all_sql_schema_patches() } ); # 0 probably means $ENV{'EHIVE_ROOT_DIR'} not set correctly
88 }
89 
90 1;
91 
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