class Workarea::MagentoMigrator::SqlConnection
Sql connection configuration
Basic format should look something like this:
sql_connection do adapter "mysql" host "localhost" username "root" password "passw0rd" database "my_database" end
Possible attributes:
adapter host database username password port encoding socket batch_size
Constants
- CUSTOMER_QUERY
- REQUIRED_FIELDS
List of required fields to bulid a valid sql connection
Attributes
client[RW]
magento_db_config[RW]
Public Class Methods
new()
click to toggle source
# File lib/workarea/magento_migrator/sql_connection.rb, line 48 def initialize() @magento_db_config = YAML.load_file("#{MagentoMigrator::Engine.root}/config/magento_db_config.yml")[Rails.env] @magento_db_config['batch_size'] ||= 10000 setup_mysql_client end
Public Instance Methods
migrate_customers()
click to toggle source
# File lib/workarea/magento_migrator/sql_connection.rb, line 63 def migrate_customers if @client customers = @client.query(CUSTOMER_QUERY) customers.each do |customer| Workarea::User.create_from_magento_customer(customer.symbolize_keys) end else Rails.logger.error(Mysql2::ConnectionError) end end
setup_mysql_client()
click to toggle source
Setups up an active_record connection
# File lib/workarea/magento_migrator/sql_connection.rb, line 55 def setup_mysql_client begin @client = Mysql2::Client.new(@magento_db_config.symbolize_keys) rescue => e Rails.logger.error(e.message) end end