Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fixes I made #22

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/mysql2psql/mysql_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def convert_type(type)
"varchar"
when /char/
"char"
when /(float|decimal)/
when /float/
"real"
when /decimal/
"decimal"
when /double/
"double precision"
Expand All @@ -59,6 +61,7 @@ def load_columns
fields = []
@reader.mysql.query("EXPLAIN `#{name}`") do |res|
while field = res.fetch_row do
length = -1
length = field[1][/\((\d+)\)/, 1] if field[1] =~ /\((\d+)\)/
length = field[1][/\((\d+),(\d+)\)/, 1] if field[1] =~ /\((\d+),(\d+)\)/
desc = {
Expand Down Expand Up @@ -188,4 +191,4 @@ def paginated_read(table, page_size)
end
end

end
end
19 changes: 14 additions & 5 deletions lib/mysql2psql/postgres_db_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,25 @@ def write_contents(table, reader)

if counter % 5000 == 0
@conn.put_copy_end
res = @conn.get_result
if res.cmdtuples != 5000
puts "\nWARNING: #{table.name} expected 5000 tuple inserts got #{res.cmdtuples} at row #{counter}\n"
end
@conn.exec(copy_line)
end

end
_time2 = Time.now
puts "\n#{_counter} rows loaded in #{((_time2 - _time1) / 60).round}min #{((_time2 - _time1) % 60).round}s"
# @conn.putline(".\n")
@conn.put_copy_end
if _counter && (_counter % 5000) > 0
res = @conn.get_result
if res.cmdtuples != (_counter % 5000)
puts "\nWARNING: table #{table.name} expected #{_counter % 5000} tuple inserts got #{res.cmdtuples}\n"
end
end
_time2 = Time.now
puts "\n#{table.name} #{_counter} rows loaded in #{((_time2 - _time1) / 60).round}min #{((_time2 - _time1) % 60).round}s"
end

end

end
end
4 changes: 2 additions & 2 deletions lib/mysql2psql/postgres_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def column_type_info(column)
when "boolean"
default = " DEFAULT #{column[:default].to_i == 1 ? 'true' : 'false'}" if default
"boolean"
when "float"
when "real"
default = " DEFAULT #{column[:default].nil? ? 'NULL' : column[:default].to_f}" if default
"real"
when "float unsigned"
Expand Down Expand Up @@ -140,4 +140,4 @@ def truncate(table)

end

end
end