Skip to content

Commit

Permalink
Ready for release
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviermaridat committed Apr 15, 2016
1 parent e526565 commit d66f014
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Then backup your Kanboard data:

And finally create the SQL dump file compatible with MySQL:

./kanbord-sqlite2mysql.sh <Kanboard instance physical path> > db-mysql.sql
./kanbord-sqlite2mysql.sh <Kanboard instance physical path> -o db-mysql.sql

Or you can also directly apply it to the MySQL database of your choice:

Expand Down
62 changes: 44 additions & 18 deletions kanboard-sqlite2mysql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ usage()
-h, --host MySQL database host
-u, --user MySQL database user for login
-o, --output Path to the output SQL dump compatible with MySQL
-v, --verbose Enable more verbosity
-H, --help Display this help
-v, --version Display the Kanboard SQLite2MySQL version
-V, --version Display the Kanboard SQLite2MySQL version
Example:
$PROGNAME /usr/local/share/www/kanboard -o db-mysql.sql
Expand All @@ -38,6 +39,7 @@ cmdline()
DB_PASSWORD=
DB_NAME=
OUTPUT_FILE=db-mysql.sql
IS_VERBOSE=0
if [ "$#" -lt "1" ]; then
echo 'error: missing arguments'
usage
Expand Down Expand Up @@ -70,11 +72,15 @@ cmdline()
DB_PASSWORD=$1
shift
;;
-v | --verbose )
shift
IS_VERBOSE=1
;;
-H | --help )
usage
exit 0
;;
-v | --version )
-V | --version )
version
exit 0
;;
Expand Down Expand Up @@ -140,6 +146,7 @@ sqlite_dump_table_data()
local sqliteDbFile=$1
local table=$2
local columns=`sqlite_columns ${sqliteDbFile} ${table}`

echo -e ".mode insert ${table}\nselect * from ${table};" \
| sqlite3 ${sqliteDbFile} \
| sed -e "s/INSERT INTO \([a-z_]*\)/INSERT INTO \1 (${columns})/"
Expand All @@ -150,11 +157,15 @@ sqlite_dump_table_data()
sqlite_dump_data()
{
local sqliteDbFile=$1
local prioritizedTables='projects columns links groups users tasks task_has_links subtasks comments actions'
local prioritizedTables='plugin_schema_versions projects columns links groups users tasks task_has_links subtasks comments actions'
for t in $prioritizedTables; do
# Please do not ask why: this TRUNCATE is already done elsewhere, but this table "plugin_schema_versions" seems to be refillld I don't know where... This fix the issue
if [ "plugin_schema_versions" == "${t}" ]; then
echo 'TRUNCATE TABLE plugin_schema_versions;'
fi
sqlite_dump_table_data ${sqliteDbFile} ${t}
done
for t in $(sqlite_tables ${sqliteDbFile} | grep -v -e projects -e columns -e links -e groups -e users -e tasks -e task_has_links -e subtasks -e comments -e actions); do
for t in $(sqlite_tables ${sqliteDbFile} | sed -e '/^plugin_schema_versions$/d' -e '/^projects$/d' -e '/^columns$/d' -e '/^links$/d' -e '/^groups$/d' -e '/^users$/d' -e '/^tasks$/d' -e '/^task_has_links$/d' -e '/^subtasks$/d' -e '/^comments$/d' -e '/^actions$/d'); do
sqlite_dump_table_data ${sqliteDbFile} ${t}
done
}
Expand All @@ -164,18 +175,18 @@ createMysqlDump()
local sqliteDbFile=$1

echo 'ALTER TABLE users ADD COLUMN is_admin INT DEFAULT 0;
ALTER TABLE users ADD COLUMN default_project_id INT DEFAULT 0;
ALTER TABLE users ADD COLUMN is_project_admin INT DEFAULT 0;
ALTER TABLE tasks ADD COLUMN estimate_duration VARCHAR(255) DEFAULT "";
ALTER TABLE tasks ADD COLUMN actual_duration VARCHAR(255) DEFAULT "";
ALTER TABLE project_has_users ADD COLUMN id INT DEFAULT 0;
ALTER TABLE project_has_users ADD COLUMN is_owner INT DEFAULT 0;
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE settings;
TRUNCATE TABLE users;
TRUNCATE TABLE links;
TRUNCATE TABLE plugin_schema_versions;
SET FOREIGN_KEY_CHECKS = 1;' > ${OUTPUT_FILE}
ALTER TABLE users ADD COLUMN default_project_id INT DEFAULT 0;
ALTER TABLE users ADD COLUMN is_project_admin INT DEFAULT 0;
ALTER TABLE tasks ADD COLUMN estimate_duration VARCHAR(255) DEFAULT "";
ALTER TABLE tasks ADD COLUMN actual_duration VARCHAR(255) DEFAULT "";
ALTER TABLE project_has_users ADD COLUMN id INT DEFAULT 0;
ALTER TABLE project_has_users ADD COLUMN is_owner INT DEFAULT 0;
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE settings;
TRUNCATE TABLE users;
TRUNCATE TABLE links;
TRUNCATE TABLE plugin_schema_versions;
SET FOREIGN_KEY_CHECKS = 1;' > ${OUTPUT_FILE}

sqlite_dump_data ${sqliteDbFile} >> ${OUTPUT_FILE}

Expand All @@ -187,10 +198,19 @@ SET FOREIGN_KEY_CHECKS = 1;' > ${OUTPUT_FILE}
ALTER TABLE project_has_users DROP COLUMN id;
ALTER TABLE project_has_users DROP COLUMN is_owner;' >> ${OUTPUT_FILE}

# For MySQL, we need to double the anti-slash (\\ instead of \)
# But we need to take care of Windows URL (e.g. C:\test\) in the JSON of project_activities (e.g. C:\test\" shall not become C:\\test\\" this will break the json...). Windows URL are transformed into Linux URL for this reason
cat ${OUTPUT_FILE} \
| sed -e 's/\\\\"/"/g' \
| sed -e 's/\\\\/\//g' \
| sed -e 's/\\"/##"/g' \
| sed -e 's/\\u\([[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]]\)/##u\1/g' \
| sed -e 's/\\/\//g' \
| sed -e 's/##"/\\\\"/g' \
| sed -e 's/##u\([[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]]\)/\\u\1/g' \
| sed -e 's/\/Kanboard\/Action\//\\\\Kanboard\\\\Action\\\\/g' \
| sed -e 's/\/u00/\\\\u00/g' \
| sed -e 's/\/r\/n/\\\\n/g' \
| sed -e 's/\/\//\//g' \
> db.mysql
mv db.mysql ${OUTPUT_FILE}
}
Expand All @@ -205,7 +225,11 @@ generateMysqlSchema()

fillMysqlDb()
{
mysql -h ${DB_HOSTNAME} -u ${DB_USERNAME} --password=${DB_PASSWORD} ${DB_NAME} \
local verbosity=
if [ "1" == "${IS_VERBOSE}" ]; then
verbosity="--verbose"
fi
mysql ${verbosity} -h ${DB_HOSTNAME} -u ${DB_USERNAME} --password=${DB_PASSWORD} ${DB_NAME} \
< ${OUTPUT_FILE}
}

Expand All @@ -232,3 +256,5 @@ main()
fi
}
main


0 comments on commit d66f014

Please sign in to comment.