mirror of
https://github.com/OpenNebula/one.git
synced 2026-12-05 06:33:48 +09:00
* Fix local characters for onedb fsck
* Fix charset for onedb sqlite2mysql
(cherry picked from commit 0fc9f457f2)
47 lines
1.2 KiB
Ruby
47 lines
1.2 KiB
Ruby
# Migrate SQLite Database to MySQL
|
|
module Sqlite2MySQL
|
|
|
|
PROGRESS = 1000
|
|
|
|
def convert(sqlite_db)
|
|
puts "Starting migration from SQLite to MySQL\n"
|
|
|
|
dst_encoding = table_to_nk(encoding)
|
|
|
|
sqlite_db.tables.each do |table|
|
|
@db[table].delete
|
|
|
|
records = sqlite_db[table].count
|
|
puts "> #{table} (#{records} records)"
|
|
|
|
@db.transaction do
|
|
i=0
|
|
sqlite_db[table].each do |row|
|
|
if table.to_s == 'logdb' && row[:fed_index] >= 2**64
|
|
row[:fed_index] = 2**64-1
|
|
end
|
|
|
|
if dst_encoding != 'UTF-8'
|
|
row.each {|k, v| row[k] = v.force_encoding(dst_encoding) if v.is_a? String }
|
|
end
|
|
|
|
@db[table].insert(row)
|
|
|
|
i+=1
|
|
if i % PROGRESS == 0
|
|
if i < PROGRESS+1
|
|
print " #{i}"
|
|
else
|
|
print "...#{i}"
|
|
end
|
|
end
|
|
end
|
|
puts if i > PROGRESS-1
|
|
end
|
|
end
|
|
|
|
puts "\nMigration successful."
|
|
end
|
|
|
|
end
|