简体   繁体   English

使用迁移文件将MySQL-DB-Dump导入Rails应用程序

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

I have an old PHP application with a bunch of MySQL tables. 我有一个带有一堆MySQL表的旧PHP应用程序。 I want to rewrite it with Rails(3) and want to import the old data. 我想用Rails(3)重写它并想导入旧数据。 How can I write a migration-script to import the MySQL-Dump into a sqlite DB? 如何编写迁移脚本以将MySQL转储导入sqlite数据库?

It's out of my merit to judge why migrate from mysql to sqlite3 db. 判断为什么要从mysql迁移到sqlite3 db是我的优点。 Why not run your dev environment as well in mysql? 为什么不在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

我使用DATA DB Dump(不是模式)解决了问题,并使用另一个迁移文件和create_table创建了表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM