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
9f31585a
Commit
9f31585a
authored
21 years ago
by
Arne Stabenau
Browse files
Options
Downloads
Patches
Plain Diff
The preload configured database is now automatically created if it doesnt exist on test host
parent
cfca09e6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/t/MultiTestDB.pm
+46
-22
46 additions, 22 deletions
modules/t/MultiTestDB.pm
with
46 additions
and
22 deletions
modules/t/MultiTestDB.pm
+
46
−
22
View file @
9f31585a
...
...
@@ -177,15 +177,6 @@ sub load_databases {
#create a config hash which will be frozen to a file
$self
->
{'
conf
'}
=
{};
#only unzip if there are non-preloaded datbases
UNZIP:
foreach
my
$dbtype
(
keys
%
{
$db_conf
->
{'
databases
'}})
{
if
(
!
$db_conf
->
{'
preloaded
'}
->
{
$dbtype
}
)
{
#unzip database files
$self
->
unzip_test_dbs
(
$self
->
curr_dir
.
$zip
);
last
UNZIP
;
}
}
#connect to the database
my
$locator
=
"
DBI:
"
.
$driver
.
"
:host=
"
.
$host
.
"
;port=
"
.
$port
;
my
$db
=
DBI
->
connect
(
$locator
,
$user
,
$pass
,
{
RaiseError
=>
1
});
...
...
@@ -195,10 +186,22 @@ sub load_databases {
return
;
}
#only unzip if there are non-preloaded datbases
UNZIP:
foreach
my
$dbtype
(
keys
%
{
$db_conf
->
{'
databases
'}})
{
if
((
!
exists
$db_conf
->
{'
preloaded
'}
->
{
$dbtype
}
)
||
(
!
_db_exists
(
$db
,
$db_conf
->
{'
preloaded
'}{
$dbtype
})
))
{
#unzip database files
$self
->
unzip_test_dbs
(
$self
->
curr_dir
.
$zip
);
last
UNZIP
;
}
}
#create a database for each database specified
foreach
my
$dbtype
(
keys
%
{
$db_conf
->
{'
databases
'}})
{
#don't create a database if there is a preloaded one specified
if
(
$db_conf
->
{'
preloaded
'}
->
{
$dbtype
}
)
{
if
((
$db_conf
->
{'
preloaded
'}
->
{
$dbtype
}
)
&&
(
_db_exists
(
$db
,
$db_conf
->
{'
preloaded
'}
->
{
$dbtype
}
)))
{
#copy the general config into a dbtype specific config
$self
->
{'
conf
'}
->
{
$dbtype
}
=
{};
%
{
$self
->
{'
conf
'}
->
{
$dbtype
}}
=
%$db_conf
;
...
...
@@ -214,30 +217,35 @@ sub load_databases {
$self
->
{'
conf
'}
->
{
$dbtype
}
->
{'
preloaded
'}
=
1
;
}
else
{
#create a unique random dbname
my
$dbname
=
$self
->
_create_db_name
(
$dbtype
);
print
STDERR
"
\n
Creating db
$dbname
";
unless
(
$db
->
do
("
CREATE DATABASE
$dbname
"))
{
warning
("
Could not create database [
$dbname
]
");
return
;
}
#copy the general config into a dbtype specific config
$self
->
{'
conf
'}
->
{
$dbtype
}
=
{};
%
{
$self
->
{'
conf
'}
->
{
$dbtype
}}
=
%$db_conf
;
$self
->
{'
conf
'}
->
{
$dbtype
}
->
{'
module
'}
=
$db_conf
->
{'
databases
'}
->
{
$dbtype
};
# it's not necessary to store the databases and zip bits of info
delete
$self
->
{'
conf
'}
->
{
$dbtype
}
->
{'
databases
'};
delete
$self
->
{'
conf
'}
->
{
$dbtype
}
->
{'
preloaded
'};
delete
$self
->
{'
conf
'}
->
{
$dbtype
}
->
{'
zip
'};
#create a unique random dbname
my
$dbname
=
$db_conf
->
{'
preloaded
'}
->
{
$dbtype
};
if
(
!
defined
$dbname
)
{
$dbname
=
$self
->
_create_db_name
(
$dbtype
);
delete
$self
->
{'
conf
'}
->
{
$dbtype
}
->
{'
preloaded
'};
}
else
{
$self
->
{'
conf
'}
->
{
$dbtype
}
->
{'
preloaded
'}
=
1
;
}
#store the temporary database name in the dbtype specific config
$self
->
{'
conf
'}
->
{
$dbtype
}
->
{'
dbname
'}
=
$dbname
;
print
STDERR
"
\n
Creating db
$dbname
";
unless
(
$db
->
do
("
CREATE DATABASE
$dbname
"))
{
warning
("
Could not create database [
$dbname
]
");
return
;
}
#copy the general config into a dbtype specific config
$db
->
do
("
use
$dbname
");
#load the database with data
...
...
@@ -527,6 +535,22 @@ sub save {
}
}
sub
_db_exists
{
my
(
$db
,
$db_name
)
=
@_
;
my
$db_names
=
$db
->
selectall_arrayref
(
"
show databases
"
);
for
my
$db_name_ref
(
@$db_names
)
{
if
(
$db_name_ref
->
[
0
]
eq
$db_name
)
{
return
1
;
}
}
return
0
;
}
sub
compare
{
my
(
$self
,
$dbtype
,
$table
)
=
@_
;
...
...
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