Class: DanarchyDeploy::Services::MySQL::Privileges

Inherits:
Object
  • Object
show all
Defined in:
lib/danarchy_deploy/services/mysql/privileges.rb

Class Method Summary collapse

Class Method Details

.new(mysql, options) ⇒ Object



8
9
10
11
# File 'lib/danarchy_deploy/services/mysql/privileges.rb', line 8

def self.new(mysql, options)
  sql_grants = sql_template(mysql, options)
  run_sql_grants(mysql, sql_grants, options)
end

.run_sql_grants(mysql, sql_grants, options) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/danarchy_deploy/services/mysql/privileges.rb', line 25

def self.run_sql_grants(mysql, sql_grants, options)
  # Using CLI commands for now;
  #   mysql2 requires mysql client be installed even if we won't be using it.
  # client = Mysql2::Client.new(:default_file => default_file)
  cmd = "mysql --defaults-file=#{mysql[:default_file]} -v < #{sql_grants}"
  DanarchyDeploy::Helpers.run_command(cmd, options)
end

.sql_template(mysql, options) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/danarchy_deploy/services/mysql/privileges.rb', line 13

def self.sql_template(mysql, options)
  sql_grants = '/root/.user_grants.sql'
  source = options[:deploy_dir] +
           '/templates/services/mysql/user_db_grants.sql.erb'
  templates = [{ target: sql_grants,
                 source: source,
                 variables: mysql[:privileges] }]

  DanarchyDeploy::Templater.new(templates, options)
  sql_grants
end