Files
one/src/onedb/sqlite2mysql.rb
T
Pavel Czerný ee8c6bd8be B #6297: Fix local characters for onedb (#2699)
* Fix local characters for onedb fsck
* Fix charset for onedb sqlite2mysql

(cherry picked from commit 0fc9f457f2)
2023-08-29 11:41:05 +02:00

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