Import MySQL-DB-Dump into a Rails app using a migration file

对着背影说爱祢 提交于 2019-12-24 09:48:26

问题


I have an old PHP application with a bunch of MySQL tables. I want to rewrite it with Rails(3) and want to import the old data. How can I write a migration-script to import the MySQL-Dump into a sqlite DB?


回答1:


It's out of my merit to judge why migrate from mysql to sqlite3 db. Why not run your dev environment as well in mysql? anyway, following is the script.

#!/bin/sh 

mysqldump --compact --compatible=ansi --default-character-set=binary mydbname | 
grep -v ' KEY "' | 
grep -v ' UNIQUE KEY "' | 
perl -e 'local $/;$_=<>;s/,\n\)/\n\)/gs;print "begin;\n";print;print "commit;\n"' | 
perl -pe ' 
if (/^(INSERT.+?)\(/) { 
$a=$1; 
s/\\'\''/'\'\''/g; 
s/\\n/\n/g; 
s/\),\(/\);\n$a\(/g; 
} ' | sqlite3 output.db



回答2:


I solved the Problem with a DATA DB Dump (not the schema) and create the tables with another migration file and create_table.



来源:https://stackoverflow.com/questions/3613235/import-mysql-db-dump-into-a-rails-app-using-a-migration-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!