class RedmineInstaller::Database::Base
Attributes
backup[R]
Public Class Methods
new(redmine)
click to toggle source
# File lib/redmine-installer/database.rb, line 50 def initialize(redmine) @redmine = redmine end
Public Instance Methods
backuped?()
click to toggle source
# File lib/redmine-installer/database.rb, line 54 def backuped? @backup && File.exist?(@backup) end
build()
click to toggle source
# File lib/redmine-installer/database.rb, line 100 def build data = {} data['adapter'] = adapter_name data['database'] = @database data['username'] = @username if @username.present? data['password'] = @password if @password.present? data['encoding'] = @encoding data['host'] = @host data['port'] = @port { 'production' => data, 'development' => data } end
do_restore(file)
click to toggle source
Recreate database should be done in 2 commands because of postgre's '–command' options which can do only 1 operations. Otherwise result is unpredictable.
# File lib/redmine-installer/database.rb, line 91 def do_restore(file) puts 'Database cleaning' Kernel.system drop_database_command Kernel.system create_database_command puts 'Database restoring' Kernel.system restore_command(file) end
get_parameters()
click to toggle source
# File lib/redmine-installer/database.rb, line 58 def get_parameters @database = prompt.ask('Database:', required: true) @host = prompt.ask('Host:', default: 'localhost', required: true) @username = prompt.ask('Username:', default: '') @password = prompt.mask('Password:', default: '') @encoding = prompt.ask('Encoding:', default: 'utf8', required: true) @port = prompt.ask('Port:', default: default_port, convert: lambda(&:to_i), required: true) end
make_backup(dir)
click to toggle source
# File lib/redmine-installer/database.rb, line 82 def make_backup(dir) puts 'Database backuping' @backup = File.join(dir, "#{@database}.sql") Kernel.system backup_command(@backup) end
make_config()
click to toggle source
# File lib/redmine-installer/database.rb, line 76 def make_config File.open(@redmine.database_yml_path, 'w') do |f| f.puts(YAML.dump(build)) end end
set_paramaters(definition)
click to toggle source
# File lib/redmine-installer/database.rb, line 67 def set_paramaters(definition) @database = definition['database'] @username = definition['username'] @password = definition['password'] @encoding = definition['encoding'] @host = definition['host'] @port = definition['port'] end
to_s()
click to toggle source
# File lib/redmine-installer/database.rb, line 116 def to_s "<#{class_name} #{@username}@#{@host}:#{@port} (#{@encoding})>" end