lib/forklift/transports/mysql.rb in forklift_etl-1.0.8 vs lib/forklift/transports/mysql.rb in forklift_etl-1.0.9

- old
+ new

@@ -75,23 +75,24 @@ end forklift.logger.log "wrote #{data.length} rows to `#{database}`.`#{table}`" end end - def lazy_table_create(table, data, database=current_database, primary_key='id') + def lazy_table_create(table, data, database=current_database, primary_key='id', matcher=default_matcher) keys = {} data.each do |item| item.each do |k,v| - keys[k] = sql_type(v) if keys[k].nil? + keys[k] = sql_type(v) if ( keys[k].nil? ) end end command = "CREATE TABLE `#{database}`.`#{table}` ( " command << " `#{primary_key}` int(11) NOT NULL AUTO_INCREMENT, " if ( data.first[primary_key.to_sym].nil? ) keys.each do |col, type| command << " `#{col}` #{type} DEFAULT NULL, " end command << " PRIMARY KEY (`#{primary_key}`) " + command << " , KEY `#{matcher}` (`#{matcher}`) " if keys.include?(matcher.to_sym) command << " ) " q(command) forklift.logger.log "lazy-created table `#{database}`.`#{table}`" end