Module: DbCopier

Defined in:
lib/db-copier/worker.rb,
lib/db-copier/db-copier.rb

Defined Under Namespace

Classes: Application, Worker

Class Method Summary collapse

Class Method Details

.app(&block) ⇒ Object



92
93
94
# File 'lib/db-copier/db-copier.rb', line 92

def self.app &block
  Application.new &block
end

.generate_create_table_ddl(db_conn, table_to_create_schema_from, new_table_name, only_copy_columns = []) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/db-copier/db-copier.rb', line 96

def self.generate_create_table_ddl(db_conn, table_to_create_schema_from, new_table_name, only_copy_columns = [])
  ret = String.new
  db_conn.schema(table_to_create_schema_from.to_sym).each do |col|
    col_name, col_type = col[0].to_sym, col[1][:type]
    #Skip creating this column if it was not specified in the columns to copy for this table
    next if only_copy_columns.count > 0 && !only_copy_columns.include?(col_name)
    if col[1][:primary_key]
      ret << "primary_key #{col_name.inspect}, #{col_type.to_sym.inspect}, :default => #{col[1][:default].inspect}, :null => #{col[1][:allow_null].inspect};\n"
    else
      ret << "#{col_type.to_s.capitalize} #{col_name.inspect}, :default => #{col[1][:default].inspect}, :null => #{col[1][:allow_null].inspect};\n"
    end
  end
  ret = (".create_table #{new_table_name.to_sym.inspect} do \n" + ret)
  ret << "end\n"
end