NIHVIVO-46 Re-load the MySQL database from a dump file, instead of leaving it empty for VIVO to re-populate (takes much less time).
This commit is contained in:
parent
67d69210a7
commit
cdb6fb83de
3 changed files with 358 additions and 5 deletions
|
@ -1,8 +1,8 @@
|
|||
=begin
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Stop the Vitro application, delete all MySQL tables from the Vitro database, and
|
||||
start the application again.
|
||||
Stop the Vitro application, delete all MySQL tables from the Vitro database,
|
||||
reload them from the mysqldump file, and start the application again.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
@ -21,6 +21,8 @@ Parameters:
|
|||
A user account that has authority to drop the Vitro database in MySQL.
|
||||
mysql_password
|
||||
The password for mysql_username.
|
||||
mysql_dump_file
|
||||
The path to a file that contains a mysqldump of the test data model.
|
||||
database_name
|
||||
The name of the Vitro database in MySQL.
|
||||
|
||||
|
@ -45,6 +47,7 @@ class DatabaseCleanser
|
|||
raise("Properties file must contain a value for 'website_url'") if @website_url == nil
|
||||
raise("Properties file must contain a value for 'mysql_username'") if @mysql_username == nil
|
||||
raise("Properties file must contain a value for 'mysql_password'") if @mysql_password == nil
|
||||
raise("Properties file must contain a value for 'mysql_dump_file'") if @mysql_dump_file == nil
|
||||
raise("Properties file must contain a value for 'database_name'") if @database_name == nil
|
||||
|
||||
# Check that we can connect to the MySQL database.
|
||||
|
@ -57,6 +60,17 @@ class DatabaseCleanser
|
|||
raise("Can't find the 'mysql' command!") if result == nil
|
||||
raise("Can't connect to MySQL database.") if !result
|
||||
raise("Error connecting to MySQL database.") if $?.exitstatus != 0
|
||||
|
||||
# Check that the mysqldump file exists and is readable
|
||||
if !File.exist?(@mysql_dump_file)
|
||||
raise "MySQL dump file '#{@mysql_dump_file}' does not exist."
|
||||
end
|
||||
if !File.file?(@mysql_dump_file)
|
||||
raise "MySQL dump file '#{@mysql_dump_file}' is not a file."
|
||||
end
|
||||
if !File.readable?(@mysql_dump_file)
|
||||
raise "MySQL dump file '#{@mysql_dump_file}' is not readable."
|
||||
end
|
||||
end
|
||||
|
||||
# Issue the Tomcat stop command and pause for it to take effect.
|
||||
|
@ -78,7 +92,7 @@ class DatabaseCleanser
|
|||
puts " Waiting #{@tomcat_start_delay} seconds..."
|
||||
sleep(@tomcat_start_delay)
|
||||
begin
|
||||
open(@website_url){|f|}
|
||||
open(@website_url){|f|}
|
||||
rescue Timeout::Error
|
||||
puts ">>> HTTP request timed out!"
|
||||
raise
|
||||
|
@ -86,7 +100,7 @@ class DatabaseCleanser
|
|||
puts " ... started."
|
||||
end
|
||||
|
||||
# Tell MySQL to drop the database and re-create it.
|
||||
# Tell MySQL to re-create the database and load from the dump file.
|
||||
#
|
||||
def drop_database_and_create_again()
|
||||
args = []
|
||||
|
@ -96,8 +110,20 @@ class DatabaseCleanser
|
|||
args << "--execute=drop database #{@database_name}; create database #{@database_name} character set utf8;"
|
||||
result = system("mysql", *args)
|
||||
raise("Can't find the 'mysql' command!") if result == nil
|
||||
raise("Can't clean the MySQL database: command was 'mysql' #{args}") if !result
|
||||
raise("Can't drop the MySQL database: command was 'mysql' #{args}") if !result
|
||||
raise("Error code from MySQL: #{$?.exitstatus}, command was 'mysql' #{args}") if $?.exitstatus != 0
|
||||
puts " Re-created the database."
|
||||
|
||||
args = []
|
||||
args << "--user=#{@mysql_username}"
|
||||
args << "--password=#{@mysql_password}"
|
||||
args << "--database=#{@database_name}"
|
||||
args << "--execute=source #{File.expand_path(@mysql_dump_file)};"
|
||||
result = system("mysql", *args)
|
||||
raise("Can't find the 'mysql' command!") if result == nil
|
||||
raise("Can't load the MySQL dump file: command was 'mysql' #{args}") if !result
|
||||
raise("Error code from MySQL: #{$?.exitstatus}, command was 'mysql' #{args}") if $?.exitstatus != 0
|
||||
puts " Loaded the databse from the dump file."
|
||||
end
|
||||
|
||||
# ------------------------------------------------------------------------------------
|
||||
|
@ -114,6 +140,7 @@ class DatabaseCleanser
|
|||
@website_url = properties['website_url']
|
||||
@mysql_username = properties['mysql_username']
|
||||
@mysql_password = properties['mysql_password']
|
||||
@mysql_dump_file = properties['mysql_dump_file']
|
||||
@database_name = properties['database_name']
|
||||
|
||||
sanity_checks_on_parameters()
|
||||
|
|
326
utilities/acceptance-tests/test-model/testmodeldump.sql
Normal file
326
utilities/acceptance-tests/test-model/testmodeldump.sql
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue