mysql2sqlite.rb
#!/usr/bin/env ruby
require 'rubygems'
if ARGV.size < 1 or not ARGV.all?{|e| File.exist? e} then
puts "usage: #{__FILE__} mysql_create_table.sql
MySQL の show create table などで出力したファイルを引数に指定する"
exit 2
end
open(ARGV[0],"r"){|f|
f.each_line{|line|
line = line.gsub /engine[^\s]+/, ""
line = line.gsub /character\s+set\s+'utf8'/, ""
line = line.gsub /drop\s+table\s+if\s+.+$/, ""
line = line.gsub /use.+$/, ""
line = line.gsub /lock.+$/, ""
line = line.gsub /unlock.+$/, ""
line = line.gsub /key\s+.+$/, ""
line = line.gsub /auto_increment\s/, ""
line = line.gsub /bigint\s/, "int "
line = line.gsub /unsigned\s/, ""
line = line.gsub /tinyint\s/, "boolean " #tinyint は booleanへ
line = line.gsub /default\s+.+,/, "," #tinyint にdefault 1 が設定されてるとまずいので消す
line = line.gsub /#.*$/, "" # コメントは消す
puts line
}
}
Mysqlのcreate tableをsqliteのcreate tableにざっくり変換する。