Sha256: ae85595f1cab9fc3f4cf7bd8be12be63707eef86248c5457c4e7b9c53184525a

Contents?: true

Size: 1.11 KB

Versions: 46

Compression:

Stored size: 1.11 KB

Contents

module Dataset
  module Database # :nodoc:
    
    # The interface to a mySQL database, this will capture by creating a dump
    # file and restore by loading one of the same.
    #
    class Mysql < Base
      def initialize(database_spec, storage_path)
        @database = database_spec[:database]
        @username = database_spec[:username]
        @password = database_spec[:password]
        @storage_path = storage_path
        FileUtils.mkdir_p(@storage_path)
      end
      
      def capture(datasets)
        return if datasets.nil? || datasets.empty?
        `mysqldump -u #{@username} --password=#{@password} --compact --extended-insert --no-create-db --add-drop-table --quick --quote-names #{@database} > #{storage_path(datasets)}`
      end
      
      def restore(datasets)
        store = storage_path(datasets)
        if File.file?(store)
          `mysql -u #{@username} --password=#{@password} --database=#{@database} < #{store}`
          true
        end
      end
      
      def storage_path(datasets)
        "#{@storage_path}/#{datasets.collect {|c| c.__id__}.join('_')}.sql"
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 8 rubygems

Version Path
aiwilliams-dataset-1.2.0 lib/dataset/database/mysql.rb
aiwilliams-dataset-1.3.0 lib/dataset/database/mysql.rb
aiwilliams-dataset-1.3.1 lib/dataset/database/mysql.rb
karsthammer-dataset-1.2.0 lib/dataset/database/mysql.rb
radiant-1.1.4 vendor/plugins/dataset/lib/dataset/database/mysql.rb
radiant-1.1.3 vendor/plugins/dataset/lib/dataset/database/mysql.rb
radiant-1.1.2 vendor/plugins/dataset/lib/dataset/database/mysql.rb
radiant-1.1.1 vendor/plugins/dataset/lib/dataset/database/mysql.rb
radiant-1.1.0 vendor/plugins/dataset/lib/dataset/database/mysql.rb
radiant-1.1.0.rc1 vendor/plugins/dataset/lib/dataset/database/mysql.rb
radiant-1.1.0.beta vendor/plugins/dataset/lib/dataset/database/mysql.rb
radiant-1.0.1 vendor/plugins/dataset/lib/dataset/database/mysql.rb
radiant-1.1.0.alpha vendor/plugins/dataset/lib/dataset/database/mysql.rb
radiant-1.0.0 vendor/plugins/dataset/lib/dataset/database/mysql.rb
radiant-1.0.0.rc5 vendor/plugins/dataset/lib/dataset/database/mysql.rb
radiant-1.0.0.rc4 vendor/plugins/dataset/lib/dataset/database/mysql.rb
radiant-1.0.0.rc3 vendor/plugins/dataset/lib/dataset/database/mysql.rb
kajam-1.0.3.rc2 vendor/plugins/dataset/lib/dataset/database/mysql.rb
radiant-1.0.0.rc2 vendor/plugins/dataset/lib/dataset/database/mysql.rb
radiant-1.0.0.rc1 vendor/plugins/dataset/lib/dataset/database/mysql.rb