Sha256: 00a8d50b6aa563dd0a99cee101842756750e80106b83609978cc2a775d15e929

Contents?: true

Size: 1.38 KB

Versions: 18

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

18 entries across 18 versions & 1 rubygems

Version Path
sequel-rails-1.1.0 lib/sequel_rails/storage/mysql.rb
sequel-rails-1.0.1 lib/sequel_rails/storage/mysql.rb
sequel-rails-1.0.0 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.9.17 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.9.16 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.9.15 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.9.14 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.9.13 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.9.12 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.9.11 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.9.10 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.9.9 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.9.8 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.9.7 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.9.6 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.9.5 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.9.4 lib/sequel_rails/storage/mysql.rb
sequel-rails-0.9.3 lib/sequel_rails/storage/mysql.rb