Module: DataKeeper::DatabaseConfig

Included in:
DatabaseHelper, Dumper, Loader
Defined in:
lib/data_keeper/database_config.rb

Instance Method Summary collapse

Instance Method Details

#connection_argsObject



57
58
59
60
61
# File 'lib/data_keeper/database_config.rb', line 57

def connection_args
  connection_opts = '--host=:host'
  connection_opts += ' --port=:port' if port
  connection_opts
end

#databaseObject



45
46
47
# File 'lib/data_keeper/database_config.rb', line 45

def database
  database_connection_config['database']
end

#database_connection_configObject



3
4
5
# File 'lib/data_keeper/database_config.rb', line 3

def database_connection_config
  @database_connection_config ||= DataKeeper.database_config.call
end

#docker_env_paramsObject



19
20
21
22
23
# File 'lib/data_keeper/database_config.rb', line 19

def docker_env_params
  psql_env.map do |k, v|
    "-e #{k}=#{v}"
  end.join(" ")
end

#dumper_connection_argsObject



63
64
65
66
67
# File 'lib/data_keeper/database_config.rb', line 63

def dumper_connection_args
  connection_opts = '--host=:host'
  connection_opts += ' --port=:port' if server_port
  connection_opts
end

#dumper_psql_envObject



13
14
15
16
17
# File 'lib/data_keeper/database_config.rb', line 13

def dumper_psql_env
  env = { 'PGUSER' => server_username }
  env['PGPASSWORD'] = server_password if server_password
  env
end

#hostObject



41
42
43
# File 'lib/data_keeper/database_config.rb', line 41

def host
  DataKeeper.docker_config[:pg_host] || database_connection_config['host'] || '127.0.0.1'
end

#passwordObject



37
38
39
# File 'lib/data_keeper/database_config.rb', line 37

def password
  DataKeeper.docker_config[:pg_password] || database_connection_config['password']
end

#portObject



49
50
51
# File 'lib/data_keeper/database_config.rb', line 49

def port
  DataKeeper.docker_config[:pg_port] || database_connection_config['port'] || '5432'
end

#psql_envObject



7
8
9
10
11
# File 'lib/data_keeper/database_config.rb', line 7

def psql_env
  env = { 'PGUSER' => username }
  env['PGPASSWORD'] = password if password
  env
end

#server_passwordObject



29
30
31
# File 'lib/data_keeper/database_config.rb', line 29

def server_password
  database_connection_config['password']
end

#server_portObject



53
54
55
# File 'lib/data_keeper/database_config.rb', line 53

def server_port
  database_connection_config['port'] || '5432'
end

#server_usernameObject



25
26
27
# File 'lib/data_keeper/database_config.rb', line 25

def server_username
  database_connection_config['username']
end

#usernameObject



33
34
35
# File 'lib/data_keeper/database_config.rb', line 33

def username
  DataKeeper.docker_config[:pg_user] || database_connection_config['username']
end