diff --git a/migrations/20160430062446-eventlog-add-table.js b/migrations/20160430062446-eventlog-add-table.js index c848e36ba..87e02f747 100644 --- a/migrations/20160430062446-eventlog-add-table.js +++ b/migrations/20160430062446-eventlog-add-table.js @@ -3,10 +3,10 @@ exports.up = function(db, callback) { var cmd = "CREATE TABLE eventlog(" + "id VARCHAR(128) NOT NULL," + - "source JSON," + + "source TEXT," + "creationTime TIMESTAMP," + "action VARCHAR(128) NOT NULL," + - "data JSON," + + "data TEXT," + "PRIMARY KEY (id))"; db.runSql(cmd, function (error) { diff --git a/migrations/20170731073447-eventlog-alter-data-and-source.js b/migrations/20170731073447-eventlog-alter-data-and-source.js new file mode 100644 index 000000000..1d043bda7 --- /dev/null +++ b/migrations/20170731073447-eventlog-alter-data-and-source.js @@ -0,0 +1,29 @@ +'use strict'; + +// we used to have JSON as the db type for those two, however mariadb does not support it +// and we never used any JSON related features, but have the TEXT pattern everywhere +// This ensures all old cloudrons will have the columns altered + +exports.up = function(db, callback) { + db.runSql('ALTER TABLE eventlog MODIFY data TEXT', [], function (error) { + if (error) console.error(error); + + db.runSql('ALTER TABLE eventlog MODIFY source TEXT', [], function (error) { + if (error) console.error(error); + + callback(error); + }); + }); +}; + +exports.down = function(db, callback) { + db.runSql('ALTER TABLE eventlog MODIFY data TEXT', [], function (error) { + if (error) console.error(error); + + db.runSql('ALTER TABLE eventlog MODIFY source TEXT', [], function (error) { + if (error) console.error(error); + + callback(error); + }); + }); +}; diff --git a/migrations/schema.sql b/migrations/schema.sql index a276bff61..a4ad763b8 100644 --- a/migrations/schema.sql +++ b/migrations/schema.sql @@ -116,8 +116,8 @@ CREATE TABLE IF NOT EXISTS backups( CREATE TABLE IF NOT EXISTS eventlog( id VARCHAR(128) NOT NULL, action VARCHAR(128) NOT NULL, - source JSON, /* { userId, username, ip }. userId can be null for cron,sysadmin */ - data JSON, /* free flowing json based on action */ + source TEXT, /* { userId, username, ip }. userId can be null for cron,sysadmin */ + data TEXT, /* free flowing json based on action */ creationTime TIMESTAMP, /* FIXME: precision must be TIMESTAMP(2) */ PRIMARY KEY (id)); diff --git a/src/eventlogdb.js b/src/eventlogdb.js index f08a394ef..9cf0c98a2 100644 --- a/src/eventlogdb.js +++ b/src/eventlogdb.js @@ -20,10 +20,11 @@ var assert = require('assert'), var EVENTLOGS_FIELDS = [ 'id', 'action', 'source', 'data', 'creationTime' ].join(','); -// until mysql module supports automatic type coercion function postProcess(eventLog) { + // usually we have sourceJson and dataJson, however since this used to be the JSON data type, we don't eventLog.source = safe.JSON.parse(eventLog.source); eventLog.data = safe.JSON.parse(eventLog.data); + return eventLog; }