Sha256: 45aa3f99b284944e1be3bbdf2441d1ef00bcd800e896037ef14f4a3bdf031dfe

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

namespace :db do
  namespace :sync do
    desc 'Download data from the databse into files. [commit=true/false tables=table1,table2]'
    task down: :environment do
      tables = ENV['tables'].present? ? ENV['tables'].split(',') : nil
      synchronizer = Db::Sync.new(sync_dir, tables)
      synchronizer.sync_down
    end

    desc 'Upload data from the files into the database. [commit=true/false tables=table1,table2]'
    task up: :environment do
      tables = ENV['tables'].present? ? ENV['tables'].split(',') : nil
      commit = ENV['commit'].present? ? ENV['commit'] == 'true' : nil
      synchronizer = Db::Sync.new(sync_dir, tables)
      sync_up_and_print(synchronizer, commit)
      if commit.nil? && synchronizer.log.present?
        print "Commit Changes? [y/n]\n"
        sync_up_and_print(synchronizer, true) if STDIN.gets.chomp == 'y'
      end
    end
  end
end

def self.sync_up_and_print(synchronizer, commit)
  synchronizer.sync_up(commit)
  print synchronizer.log.join("\n") + "\n"
end

def self.sync_dir
  ENV['dir']
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
db-sync-0.0.15 lib/tasks/db.rake
db-sync-0.0.14 lib/tasks/db.rake
db-sync-0.0.13 lib/tasks/db.rake