Top Level Namespace

Defined Under Namespace

Modules: CleanFindInBatches, DataTransit, RULE_DSL, TimeExt Classes: DTWorker, Time

Instance Method Summary collapse

Instance Method Details

#copy_data(rule_file) ⇒ Object



49
50
51
52
53
# File 'lib/datatransit/cli.rb', line 49

def copy_data rule_file
  worker = DTWorker.new rule_file
  worker.load_work
  worker.do_work
end

#create_tables(schema_file) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/datatransit/cli.rb', line 40

def create_tables schema_file
  puts "\npreparing to create tables in the target database\n"
  ActiveRecord::Base.establish_connection(DataTransit::Database.target)
  require schema_file
  ActiveRecord::Base.remove_connection
  puts "tables created in target database\n"
end

#dump_schema(schema_file, rule_file) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/datatransit/cli.rb', line 24

def dump_schema schema_file, rule_file
  puts "preparing to generate schema.rb, the schema of source database\n"
  ActiveRecord::Base.establish_connection(DataTransit::Database.source)
  #tables = DataTransit::Database.tables
  worker = DTWorker.new rule_file
  worker.load_work
  tables = worker.get_all_tables

  print tables, "\n"

  dumper = DataTransit::ModelDumper.new tables
  dumper.dump_tables File.open(schema_file, 'w');
  ActiveRecord::Base.remove_connection
  puts "schema.rb generated\n"
end

#setup_db_conn(db_yml) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/datatransit/cli.rb', line 55

def setup_db_conn db_yml
  if File::exists? db_yml
    src = File::open(db_yml, "r")
    dst = File::open( File.expand_path('../../../database.yml', __FILE__), "w" )
    
    src.each_line { |line|
       dst.write line
    }
    src.close
    dst.close
  end
end