Created
February 8, 2012 16:08
-
-
Save takuya/1770758 to your computer and use it in GitHub Desktop.
MySQLをSqliteに変換する。 ref: http://qiita.com/items/2197
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment