[typo] Help with mysql and installer

Phillip Toland phil.toland at gmail.com
Thu Aug 10 15:09:21 EDT 2006


On 8/10/06, Scott Laird <scott at sigkill.org> wrote:
> I'd like to get native mysql support into the installer.  I'd really
> like to get it in *today*.  So I'd like some help.  It's not all that
> complex--here's the important part of the postgres driver:
[snip]

How's this:

class Mysql < RailsInstaller::Database
  def self.db_host(installer)
    installer.config['db_host'] || 'localhost'
  end

  def self.db_user(installer)
    installer.config['db_user'] || installer.app_name
  end

  def self.db_name(installer)
    installer.config['db_name'] || installer.app_name
  end

  def self.yml(installer)
    %Q{
    login: &login
      adapter: mysql
      host: #{db_host installer}
      username: #{db_user installer}
      password: #{installer.config['db_password']}
      database: #{db_name installer}

    development:
      <<: *login

    production:
      <<: *login

    test:
      database: #{db_name installer}-test
      <<: *login
    }
  end

  # Create a MySQL database.
  def self.create_database(installer)
    installer.message "Creating MySQL database"
    system("mysql -u #{db_user installer}
-p#{installer.config['db_password']} -e 'create database #{db_name
installer}'")
    system("mysql -u #{db_user installer}
-p#{installer.config['db_password']} -e 'create database #{db_name
installer}-test'")
  end
end


Phil


More information about the Typo-list mailing list