Class: App::MySQL
- Inherits:
-
Object
- Object
- App::MySQL
- Defined in:
- lib/core/mysql.rb
Constant Summary collapse
- DEFAULT_VM_SCHEMA =
'app'
- DEFAULT_EC2_SCHEMA =
'brightpearl'
Class Method Summary collapse
- .ec2(schema = DEFAULT_EC2_SCHEMA) ⇒ Object
- .get_random_customer_id ⇒ Object
- .get_random_shipping_id ⇒ Object
- .vm(schema = DEFAULT_VM_SCHEMA) ⇒ Object
Class Method Details
.ec2(schema = DEFAULT_EC2_SCHEMA) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/core/mysql.rb', line 30 def self.ec2(schema = DEFAULT_EC2_SCHEMA) if @ec2_connection.nil? encrypter = Encrypter.new host = App::Config.param(App::Config::EC2_HOST) user = App::Config.param(App::Config::EC2_USER) pass = App::Config.param(App::Config::EC2_PASS) if host.nil? || user.nil? || pass.nil? || host == '' || user == '' || pass == '' App::Terminal::error('EC2 access data not found', ["The command you're trying to run requires access to an EC2 database.", "In order for this to work you will need valid #{App::Terminal::format_highlight('access data')}.", "Please speak to #{App::Terminal::format_highlight('Albert')} (or team Raptor) for more info."], true) end @ec2_connection = Mysql2::Client.new( :host => encrypter.decrypt(host), :username => encrypter.decrypt(user), :password => encrypter.decrypt(pass), :database => schema ) end @ec2_connection end |
.get_random_customer_id ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/core/mysql.rb', line 52 def self.get_random_customer_id unless @ids_customers.any? customers = App::MySQL::vm.query('SELECT customers_id FROM customers ORDER BY customers_id DESC LIMIT 100') customers.each do |row| @ids_customers << row['customers_id'] end end @ids_customers.sample end |
.get_random_shipping_id ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/core/mysql.rb', line 62 def self.get_random_shipping_id unless @ids_shipping.any? ship_methods = App::MySQL::vm.query('SELECT ship_method_id FROM ship_methods ORDER BY ship_method_id DESC LIMIT 100') ship_methods.each do |row| @ids_shipping << row['ship_method_id'] end end @ids_shipping.sample end |
.vm(schema = DEFAULT_VM_SCHEMA) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/core/mysql.rb', line 16 def self.vm(schema = DEFAULT_VM_SCHEMA) if @vm_connection[schema].nil? @vm_connection[schema] = Mysql2::Client.new( :host => App::Config.param(App::Config::VM_IP), :username => App::Config.param(App::Config::VM_MYSQL_USER), :password => App::Config.param(App::Config::VM_MYSQL_PASSWORD), :database => schema ) end @vm_connection[schema] end |