-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# This scipt converts a MySQL to a SQLite database. It assumes both | ||
# old and new databases live on the same host and are accessable by the same | ||
# user. | ||
|
||
SCHEMA=../../src/db/schema.sqlite | ||
|
||
DB_IN="" | ||
DB_OUT="" | ||
DB_HOST="localhost" | ||
DB_USR="test" | ||
DB_PWD="test" | ||
|
||
while getopts "i:o:h:u:p:" arg; do | ||
case $arg in | ||
i) DB_IN=$OPTARG ;; | ||
o) DB_OUT=$OPTARG ;; | ||
h) DB_HOST=$OPTARG ;; | ||
u) DB_USR=$OPTARG ;; | ||
p) DB_PWD=$OPTARG ;; | ||
*) | ||
echo "usage: "$0" -i DATABASE_1.4 -o DATABASE_2.0 [-h HOST] [-u USER] [-p PASSWORD]" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
if [ -z $DB_IN ]; then | ||
echo "ERROR: No input database specified (-i DB_NAME)" | ||
exit 1 | ||
fi | ||
|
||
if [ -z $DB_OUT ]; then | ||
echo "ERROR: No output database specified (-o DB_FILE)" | ||
exit 1 | ||
fi | ||
|
||
rm -f $DB_OUT | ||
sqlite3 $DB_OUT < $SCHEMA | ||
echo "attach '$DB_IN' as REMOTE;" | | ||
cat - sqlite_convert.sql | sqlite3 $DB_OUT | ||
|
||
echo "Converting database" | ||
|
||
mysqldump -u $DB_USR -p$DB_PWD -h $DB_HOST $DB_IN |grep INSERT | sed -r 's/^INSERT INTO `([^"]+)`/INSERT INTO "\1"/' > tmp | ||
sqlite3 $DB_OUT < tmp | ||
rm tmp |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# This scipt converts a SQLite3 to a MySQL database. It assumes both | ||
# old and new databases live on the same host and are accessable by the same | ||
# user. | ||
|
||
SCHEMA=../../src/db/schema.mysql | ||
|
||
DB_IN="" | ||
DB_OUT="" | ||
DB_HOST="localhost" | ||
DB_USR="test" | ||
DB_PWD="test" | ||
|
||
while getopts "i:o:h:u:p:" arg; do | ||
case $arg in | ||
i) DB_IN=$OPTARG ;; | ||
o) DB_OUT=$OPTARG ;; | ||
h) DB_HOST=$OPTARG ;; | ||
u) DB_USR=$OPTARG ;; | ||
p) DB_PWD=$OPTARG ;; | ||
*) | ||
echo "usage: "$0" -i DATABASE_1.4 -o DATABASE_2.0 [-h HOST] [-u USER] [-p PASSWORD]" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
if [ -z $DB_IN ]; then | ||
echo "ERROR: No input database specified (-i DB_FILE)" | ||
exit 1 | ||
fi | ||
|
||
if [ -z $DB_OUT ]; then | ||
echo "ERROR: No output database specified (-o DB_NAME)" | ||
exit 1 | ||
fi | ||
|
||
echo "Creating database $DB_OUT (as user $DB_USR)" | ||
echo "DROP DATABASE IF EXISTS $DB_OUT;CREATE DATABASE $DB_OUT;" | | ||
mysql -u $DB_USR -p$DB_PWD -h $DB_HOST | ||
|
||
echo "Creating tables in $DB_OUT (as user $DB_USR)" | ||
mysql -u $DB_USR -p$DB_PWD -h $DB_HOST $DB_OUT < $SCHEMA | ||
|
||
echo "Converting database" | ||
|
||
sqlite3 $DB_IN .dump | grep INSERT | grep -v sqlite_sequence | sed -r 's/^INSERT INTO "([^"]+)"/INSERT INTO `\1`/' > tmp | ||
mysql -u $DB_USR -p$DB_PWD -h $DB_HOST $DB_OUT < tmp | ||
rm tmp |