Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

migration helper to convert existing openbadges databases to utf8

  • Loading branch information...
commit 3bbe6538e7826a1b550c319ac0ce2d6771d24b48 1 parent c5d8cb1
Mike Larsson stenington authored
Showing with 37 additions and 0 deletions.
  1. +37 −0 bin/db_to_utf8.js
37 bin/db_to_utf8.js
View
@@ -0,0 +1,37 @@
+var client = require('../lib/mysql').client;
+var conf = require('../lib/configuration').get('database');
+
+var ENCODING = 'utf8';
+
+var statements = [];
+statements.push("ALTER DATABASE `" + conf.database + "` CHARACTER SET " + ENCODING + ";");
+var tables = ['user', 'badge', 'group', 'portfolio'];
+tables.forEach(function (table) {
+ statements.push("ALTER TABLE `" + table + "` CONVERT TO CHARACTER SET " + ENCODING + ";");
+});
+
+runEach(statements, function(){ process.exit(0); });
+
+function runEach(statements, done) {
+ var i = 0;
+
+ function run(index) {
+ return function(err){
+ if(err) {
+ throw err;
+ }
+ if(index < statements.length) {
+ var statement = statements[index];
+ console.log(statement);
+ client.query(statement, run(index+1));
+ }
+ else {
+ done();
+ }
+ };
+ }
+
+ run(0)();
+}
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.