Sha256: f684de26ab721964f5e1ee3b16c1a302096035f83f593b6c9d08350c55b87af1

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

module Lotus
  module Model
    module Migrator
      # MySQL adapter
      #
      # @since 0.4.0
      # @api private
      class MySQLAdapter < Adapter
        # @since 0.4.0
        # @api private
        def create
          new_connection.run %(CREATE DATABASE #{ database };)
        end

        # @since 0.4.0
        # @api private
        def drop
          new_connection.run %(DROP DATABASE #{ database };)
        rescue Sequel::DatabaseError => e
          message = if e.message.match(/doesn\'t exist/)
            "Cannot find database: #{ database }"
          else
            e.message
          end

          raise MigrationError.new(message)
        end

        # @since 0.4.0
        # @api private
        def dump
          dump_structure
          dump_migrations_data
        end

        # @since 0.4.0
        # @api private
        def load
          load_structure
        end

        private

        # @since 0.4.0
        # @api private
        def dump_structure
          system "mysqldump --user=#{ username } --password=#{ password } --no-data --skip-comments --ignore-table=#{ database }.#{ migrations_table } #{ database } > #{ schema }"
        end

        # @since 0.4.0
        # @api private
        def load_structure
          system "mysql --user=#{ username } --password=#{ password } #{ database } < #{ escape(schema) }" if schema.exist?
        end

        # @since 0.4.0
        # @api private
        def dump_migrations_data
          system "mysqldump --user=#{ username } --password=#{ password } --skip-comments #{ database } #{ migrations_table } >> #{ schema }"
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lotus-model-0.4.1 lib/lotus/model/migrator/mysql_adapter.rb
lotus-model-0.4.0 lib/lotus/model/migrator/mysql_adapter.rb