DSL to dump production data for developer use.
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
.rspec
.travis.yml
Gemfile
LICENSE.txt
README.md
Rakefile
dump_truck.gemspec

README.md

DumpTruck

A simple DSL to specify how to dump data from a production environment for use in a developer environment. Provides tools to limit what data is pulled and obfuscate data that is pulled.

Installation

Add this line to your application's Gemfile:

gem 'dump_truck'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dump_truck

Usage

Create a ruby file that looks like this:

require 'logger'

DumpTruck.configure do
  # You can optionally provide a logger. If no logger is provided,
  # information will be logged to standard out.
  logger Logger.new('dump.log')

  # You can specify an arbitrary number of databases to connect to
  database(:mysql) do
    # Where and how to connect
    hostname ENV['hostname']
    user ENV['user']
    password ENV['password'] # pass nil if there is no password

    # The schemas to dump from this database.
    schema 'app_production' do
      # Directory to place the resulting sql dump
      target_path ENV['target_path']

      # File name for this schema sql dump. '.sql' is appended
      # automatically to the name. If unspecified, the name of the schema
      # is used.
      target_file{|schema| schema + Time.now.strftime("_%Y%m%d%H%M%S")}

      # Tables rules can be defined to have one of four modes:
      # * keep - all data for that table is dumped
      # * keep 'some query' - data that satifies the query is dumped
      # * truncate - no data is dumped
      # * ignore - the table and data are not dumped
      #
      # Tables also define obfuscation rules. If no rules is defined for
      # a column, the value is dumped as is. Obfuscation rules can
      # optionally receive the value and a number which will be unique
      # for each row of that table. If an obfuscation rule is defined for
      # a field that doesn't exist for the table, it is ignored. This
      # is most useful for the default table rule, because it allows
      # obfuscation of all email fields for tables that have them.
      #
      # The default table rule is applied to any table that does not have
      # a rule defined. Otherwise, it behaves like any other table rule.

      table_default do
        keep "created_at > now() - interval 6 month"

        obfuscate(:email){|email, n| "my.email+#{n}@gmail.com"}
      end

      table(:users) do
        keep

        obfuscate(:email){|email, n| "my.email+#{n}@gmail.com"}
        obfuscate(:password){'password'}
        obfuscate(:name){|name| name.split('').shuffle.join}
      end

      table(:delayed_jobs){keep "deleted_at is null"}
      table(:roles){keep}
      table(:emails){truncate}
      table(:credit_cards){ignore}
    end
  end
end

Contributing

  1. Fork it ( http://github.com/secondrotation/dump_truck/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request