40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/thredded/db_tools.rb', line 40
def restore(from = dump_file)
case adapter
when /postgres/i
cmd = [
'pg_restore --verbose --clean --no-owner --no-acl',
"--dbname=postgresql://#{username}:#{password}@#{host}:5432/#{database}",
from,
'>',
Rails.root.join('log', 'restore.log')
].join(' ')
system cmd
when /mysql/i, /sqlite/i
connection = ActiveRecord::Base.connection
statements = File.read(from).split(/;$/)
statements.pop
silence_active_record do
ActiveRecord::Base.transaction do
statements.each do |statement|
connection.execute(statement) unless /(BEGIN TRANSACTION|COMMIT)/.match?(statement)
end
end
end
end
end
|