views:

21

answers:

2

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?

A: 

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
VP
Hm, that doesn't work quite well. (syntax error with "auto_increment", "unsigned", ...) Is there a better way?
Fu86
A: 

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

Fu86