Sha256: 2944cff4c7499ca5a12a84eecd57fa1921493730c334b98c6422c0cbc8fe3e13

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

module SequelRails
  module Storage
    class Mysql < Abstract
      def _create
        execute "CREATE DATABASE IF NOT EXISTS `#{database}` DEFAULT CHARACTER SET #{charset} DEFAULT COLLATE #{collation}"
      end

      def _drop
        execute "DROP DATABASE IF EXISTS `#{database}`"
      end

      def _dump(filename)
        commands = ['mysqldump']
        add_connection_settings commands
        add_flag commands, '--no-data'
        add_option commands, '--result-file', filename
        commands << database
        safe_exec commands
      end

      def _load(filename)
        commands = ['mysql']
        add_connection_settings commands
        add_option commands, '--database', database
        add_option commands, '--execute', %{SET FOREIGN_KEY_CHECKS = 0; SOURCE #{filename}; SET FOREIGN_KEY_CHECKS = 1}
        safe_exec commands
      end

      def collation
        @collation ||= super || 'utf8_unicode_ci'
      end

      private

      def add_connection_settings(commands)
        add_option commands, '--user', username
        add_option commands, '--password', password
        add_option commands, '--host', host
        add_option commands, '--port', port.to_s
      end

      def execute(statement)
        commands = ['mysql']
        add_connection_settings commands
        add_option commands, '--execute', statement
        safe_exec commands
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sequel-rails-0.9.2 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.9.1 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.9.0 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.8.0 lib/sequel_rails/storage/mysql.rb