lib/fulmar/infrastructure/service/database/database_service.rb in fulmar-1.5.2 vs lib/fulmar/infrastructure/service/database/database_service.rb in fulmar-1.6.0
- old
+ new
@@ -71,16 +71,18 @@
@client.query "CREATE DATABASE IF NOT EXISTS `#{name}`"
disconnect unless state_before
end
def dump(filename = backup_filename)
+ filename = "#{@config[:remote_path]}/#{filename}" unless filename[0, 1] == '/'
+
diffable = @config[:maria][:diffable_dump] ? '--skip-comments --skip-extended-insert ' : ''
@shell.run "mysqldump -h #{@config[:maria][:host]} -u #{@config[:maria][:user]} --password='#{@config[:maria][:password]}' " \
"#{@config[:maria][:database]} --single-transaction #{diffable}-r \"#{filename}\""
- @config[:remote_path] + '/' + filename
+ filename
end
def load_dump(dump_file, database = @config[:maria][:database])
@shell.run "mysql -h #{@config[:maria][:host]} -u #{@config[:maria][:user]} --password='#{@config[:maria][:password]}' " \
"-D #{database} < #{dump_file}"
@@ -94,9 +96,28 @@
if copy
local_path
else
''
end
+ end
+
+ def clear
+ clear_statements = <<-EOD.gsub(/^\s+\|/, '')
+ |SET FOREIGN_KEY_CHECKS = 0;
+ |SET GROUP_CONCAT_MAX_LEN=32768;
+ |SET @tables = NULL;
+ |SELECT GROUP_CONCAT('`', table_name, '`') INTO @tables
+ |FROM information_schema.tables
+ |WHERE table_schema = (SELECT DATABASE());
+ |SELECT IFNULL(@tables,'dummy') INTO @tables;
+ |
+ |SET @tables = CONCAT('DROP TABLE IF EXISTS ', @tables);
+ |PREPARE stmt FROM @tables;
+ |EXECUTE stmt;
+ |DEALLOCATE PREPARE stmt;
+ |SET FOREIGN_KEY_CHECKS = 1;
+ EOD
+ @client.query clear_statements
end
protected
def try_connect(options, i)